2011-12-14 128 views
0

我能够在应用中拍摄'图片截图',但我需要在该图片中截取'特定部分'的截图。请谁能帮助我这样做...谢谢... 这里是我使用的拍摄图像的屏幕截图的代码....捕捉屏幕截图图片'Android'

L1 = (LinearLayout) findViewById(R.id.LinearLayout01); 
Button but = (Button) findViewById(R.id.Button01); 
but.setOnClickListener(new View.OnClickListener() { 

    @Override 

    public void onClick(View v) { 

     View v1 = L1.getRootView(); 

     v1.setDrawingCacheEnabled(true); 

     Bitmap bm = v1.getDrawingCache(); 

     BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); 
     image = (ImageView) findViewById(R.id.ImageView01); 

     image.setBackgroundDrawable(bitmapDrawable); 

    } 

}); 

`

+0

检查我的答案[这里](http://stackoverflow.com/questions/8294110/taking-screenshot/8366223#8366223) – 2011-12-14 13:34:46

回答

0

得到位图后做这种方式

Bitmap new_bmp = Bitmap.createBitmap(bm, 0, 0, linear.getWidth(), linear.getHeight(), matrix, false); 

      image.draw(new Canvas(new_bmp)); 
      String s = Environment.getExternalStorageDirectory().toString(); 

      linear.setBackgroundColor(Color.BLACK); 
      OutputStream outStream = null; 
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss"); 
      String file_name = sdf.format(new Date())+".PNG"; 
      File file = new File(s, file_name); 
      try { 
      outStream = new FileOutputStream(file); 
      new_bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
      outStream.flush(); 
      outStream.close(); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
       Toast.makeText(CaptureImage.this, e.toString(), Toast.LENGTH_LONG).show(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
       Toast.makeText(CaptureImage.this, e.toString(), Toast.LENGTH_LONG).show(); 
      }