【发布时间】:2017-07-05 22:24:08
【问题描述】:
我正在尝试在我的应用程序中实现 png 图片的共享选项,但我收到了 TransactionTooLargeException。我做了什么:我添加了代码来压缩我的位图,但我仍然得到异常。是不是我做错了什么?
public void sharePicture(MenuItem shareItem) {
MenuItemCompat.getActionProvider(shareItem);
Drawable drawable = itemImage.getDrawable();
Bitmap picture = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
picture.compress(Bitmap.CompressFormat.PNG, 100, stream);
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, picture);
startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
【问题讨论】:
-
我添加了代码来压缩我的位图 ...不,您不这样做,因为您不能...您将位图保存/压缩到您从未使用过的流中再次使用它......位图将始终占用
width * heigth * bytes_per_pixel内存
标签: java android bitmap png share