Bitmap image = Bitmap.createBitmap(_view.getWidth(), _view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
android.graphics.drawable.Drawable bgDrawable = _view.getBackground();
if (bgDrawable!=null) {
bgDrawable.draw(canvas);
} else{
canvas.drawColor(Color.WHITE);
}
_view.draw(canvas);
java.io.File pictureFile = new java.io.File(getExternalCacheDir() + "/image.jpg");
if (pictureFile == null) {
Log.d("MainActivity", "Error creating media file, check storage permissions: ");
return;
}
try {
java.io.FileOutputStream fos = new java.io.FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (java.io.FileNotFoundException e) {
Log.d("MainActivity", "File not found: " + e.getMessage());
} catch (java.io.IOException e) {
Log.d("MainActivity", "Error accessing file: " + e.getMessage());
}
Intent iten = new Intent(android.content.Intent.ACTION_SEND);
iten.setType("*/*");
iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg")));
startActivity(Intent.createChooser(iten, "Send image"));
Canvas canvas = new Canvas(image);
android.graphics.drawable.Drawable bgDrawable = _view.getBackground();
if (bgDrawable!=null) {
bgDrawable.draw(canvas);
} else{
canvas.drawColor(Color.WHITE);
}
_view.draw(canvas);
java.io.File pictureFile = new java.io.File(getExternalCacheDir() + "/image.jpg");
if (pictureFile == null) {
Log.d("MainActivity", "Error creating media file, check storage permissions: ");
return;
}
try {
java.io.FileOutputStream fos = new java.io.FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (java.io.FileNotFoundException e) {
Log.d("MainActivity", "File not found: " + e.getMessage());
} catch (java.io.IOException e) {
Log.d("MainActivity", "Error accessing file: " + e.getMessage());
}
Intent iten = new Intent(android.content.Intent.ACTION_SEND);
iten.setType("*/*");
iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg")));
startActivity(Intent.createChooser(iten, "Send image"));
Video Help
Tags:
Java image share code