从屏幕底部裁剪位图 150dp 到屏幕顶部



我正在使用屏幕截图,并希望从屏幕底部以编程方式裁剪 150dp位图。 (从屏幕底部擦除位图150dp(

怎么做?

这是图像解释:https://i.stack.imgur.com/vwhUp.jpg

已编辑。截屏的完整代码:

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();
}
}

我很困惑。 谢谢

试试这段代码

调用此方法,传入要获得其屏幕截图的最外层 ViewGroup:

public Bitmap screenShot(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
150, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}

有关更多信息,您也可以查看此答案

最新更新