尝试共享图像文件时,我不断收到此错误:
java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1085992字节
我假设一个解决方案是将图像压缩得更多,这会减小尺寸.这是完成这项工作的功能:
public static File saveBitmaptoFile(Bitmap bitmap, File pictureFile) {
FileOutputStream out = null;
try {
out = new FileOutputStream(pictureFile);
// on the next line I'm trying compress the heck out of image.
bitmap.compress(Bitmap.CompressFormat.JPEG, 1, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pictureFile;
}
Run Code Online (Sandbox Code Playgroud)
这是共享功能:
private void shareToInstagram() {
String type = "image/png";
Intent share = new Intent(Intent.ACTION_SEND); …Run Code Online (Sandbox Code Playgroud)