2011-12-14 106 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(); 
      }