I'm having an ImageView
in which I'm having a bitmap
. I'm storing it in Internal Storage in the form of .png and then want to share using shareIntent
. But when trying to share, it is retrieving me a black image rather than a QR code which was my original image.
This is how I'm generating QR Code and displaying it in ImageView
:
try {
BitMatrix bitMatrix = multiFormatWriter.encode(text,BarcodeFormat.QR_CODE,500,500);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap_img = barcodeEncoder.createBitmap(bitMatrix);
iv.setBackgroundColor(Color.WHITE); // iv is the ImageView
iv.setImageBitmap(bitmap_img);
bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap();
} catch (Exception r) { r.printStackTrace(); }
In share button:
try {
File imagesFolder = new File(getCacheDir(), "images");
File file = new File(imagesFolder, "shared_image.png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
iv.setImageBitmap(bitmap); // iv is the ImageView
fOut.flush();
fOut.close();
savedImageURI = Uri.parse(file.getPath());
file.setReadOnly(); //Readable(true, false);
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, savedImageURI);
intent.setType("image/png");
startActivity(Intent.createChooser(intent, "Share image via"));
} catch (Exception e) { e.printStackTrace(); }