2011-03-16 14 views

回答

1

您可以查看[email protected]的代码,了解如何使用USB从屏幕截取屏幕截图。请注意,这种支持没有记录,仍然需要在主机上安装Android SDK。

+0

感谢üCommonsWare分享UR知识。 – 2011-03-24 10:32:17

0

使用monkeyrunner和这样的脚本将完成这项工作。

#! /opt/android-sdk-linux_86/tools/monkeyrunner 

# Imports the monkeyrunner modules used by this program 
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice 
# Connects to the current device, returning a MonkeyDevice object 
device = MonkeyRunner.waitForConnection() 
# Takes a screenshot 
result = device.takeSnapshot() 
# Writes the screenshot to a file 
result.writeToFile('/tmp/device.png','png') 
+0

我得到的代码DDMS ..所以即时通讯它完成它..但现在面临的问题是,屏幕的大小更多..宽度是480,但高度来了1536000 ..所以它要走了越界.. – 2011-03-17 08:30:08

0
First call this method oncreate(); 
new screenshot().execute(); 


after create given class: 


     class screenshot extends AsyncTask<String, String, String> { 


      @Override 
      protected void onPreExecute() { 

       super.onPreExecute(); 


      } 

      @Override 
      protected String doInBackground(String... args) { 

       Log.e("Screenshot", "Called"); 

       mView = view.getRootView(); 
       mView.setDrawingCacheEnabled(true); 
       b = mView.getDrawingCache(); 

       String extr = Environment.getExternalStorageDirectory().toString(); 
       File myPath = new File(extr, getString("myapp") 
         + ".jpg"); 
       Log.e("My_PatH", "" + myPath); 
       if (myPath.exists()) 
        myPath.delete(); 
       FileOutputStream fos = null; 
       try { 
        fos = new FileOutputStream(myPath); 
        b.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
        fos.flush(); 
        fos.close(); 
        MediaStore.Images.Media.insertImage(getContentResolver(), b, 
          "Screen", "screen"); 
        Log.e("Bitmap", "" + b); 
        Log.e("myPath", "" + myPath); 
       } catch (FileNotFoundException e) { 

        e.printStackTrace(); 
       } catch (Exception e) { 

        e.printStackTrace(); 
       } 
       return null; 
      } 

      protected void onPostExecute(String args) { 

      } 
     } 
相关问题