从屏幕底部到屏幕顶部裁剪位图150dp
问题描述:
我使用屏幕截图,并且想要以编程方式裁剪位图从屏幕底部 150dp。 (擦除从屏幕底部的位图150dp)从屏幕底部到屏幕顶部裁剪位图150dp
如何做到这一点?
这是形象的解释:http://imgur.com/TP2ouVp
编辑。对于采取截屏全码:
public void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
String folder_main = "APP_FOLDER";
File f = new File(Environment.getExternalStorageDirectory(), folder_main);
if (!f.exists()) {
f.mkdirs();
}
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/APP_FOLDER/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap source = v1.getDrawingCache();
int x = 0;
int y = v1.getHeight() ;
int width = source.getWidth() - x;
int height = source.getHeight() - y;
Bitmap bitmap = Bitmap.createBitmap(source, x, y, width, height);
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
openScreenshotWhatsApp (imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
}
我很困惑。 感谢
你有没有尝试过这个int height = source.getHeight() - 150; –
你是否能够截图的任何部分? –
使用该代码,无法创建屏幕截图。 但与此代码完成的:。 //创建位图截屏 \t查看V1 = getWindow()getDecorView()getRootView(); \t v1.setDrawingCacheEnabled(真); \t位图的位图= Bitmap.createBitmap(v1.getDrawingCache()); \t v1.setDrawingCacheEnabled(假); – Bonnie7