【问题标题】:Capturing Screenshot Image 'Android'捕获屏幕截图图像“Android”
【发布时间】:2012-01-20 06:36:32
【问题描述】:
我可以在我的应用中截取“图像截图”,但我需要截取该图像中“特定部分”的截图。请任何人帮助我做到这一点...谢谢...
这是我用来截取图像的代码......
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);
}
});
`
【问题讨论】:
标签:
android
image
screenshot
【解决方案1】:
获取位图后这样做
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();
}