Reputation: 29
I am use screen capture, and want to crop bitmap programatically 150dp from bottom of screen. (Erase bitmap 150dp from bottom of screen)
How to do that?
This is image explanation: https://i.sstatic.net/vwhUp.jpg
Edited. Full code for take screen shot:
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();
}
}
I'm very confusing. Thanks
Upvotes: 0
Views: 199
Reputation: 18775
Try this code
Call this method, passing in the outer most ViewGroup that you want a screen shot of:
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;
}
For more you can check this answers as well
Upvotes: 1