【发布时间】:2018-10-28 06:08:42
【问题描述】:
我有一个ImageView,其中我有一个bitmap。我以 .png 的形式将其存储在 Internal Storage 中,然后想使用shareIntent 共享。但是在尝试分享时,它正在检索我的黑色图像,而不是我原始图像的 QR 码。
这就是我生成二维码并将其显示在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(); }
在分享按钮中:
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(); }
【问题讨论】:
-
请参考这个link
标签: android android-imageview android-bitmap android-file android-sharing