I'm taking snapshots and creat thumbnails and then share this image. But the thumbnail shows all black. I have used the following code
Bitmap bitmap;
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
String url = Images.Media.insertImage(
mContext.getContentResolver(), bitmap, "title", null);
Can anyone tell me what is wrong with this code.
EDIT
private View.OnClickListener shareListener = new View.OnClickListener() {
public void onClick(View v) {
Bitmap bitmap;
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
String url = Images.Media.insertImage(
mContext.getContentResolver(), bitmap, "title", null);
v1.setDrawingCacheEnabled(false);
Activity activity = (Activity) getContext();
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
activity.startActivity(Intent.createChooser(share,
"Share"));
}
};
Black Image
Use Hotkey Combination. If pressing single PrtSc key doesn't work, you can try the following keyboard shortcut buttons: Alt key + PrintScreen: This hotkeys button will capture the currently selected window and allow you to save this image by using the paint or any other editing application.
To do this, you simply have to go to "Settings / Display / Dark Mode"And disable the toggle"Adjust contrast automatically".
Using coding, websites can log when and of what part of the website you took your screenshot, and in some cases, it can tell them even more (such as what browser you are using). Netflix and other streaming service websites such as Hulu and others are commonly used websites that block screenshots.
Use following code it may work for you. Thanks
SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);
// Draw background
background.draw(canvas);
// Draw views
view.draw(canvas);
// Save the screenshot to the file system
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With