【发布时间】:2018-05-07 11:55:26
【问题描述】:
我有两个应用程序,应用程序 A 和应用程序 B。当我按下应用程序 A 中的按钮时,将调用应用程序 B。在应用程序 B 中,它具有相机活动和其他一些图像处理选项,例如裁剪、调整亮度和对比度。图像处理后,我需要将图像传递给 App A。但是,图像不应该保存在 sd 卡中。
我尝试了什么:使用图像到 base64 字符串
第 1 步:我使用此代码调用了 AppB
Intent i = new
Intent("com.appb.ImageProcessingActivity");
startActivityForResult(i, 100);
Step2: 在 App B 中,经过图像处理,我将图像转换为 base64 字符串并使用此代码将其发送回 App A。 (图像处理后,图像大小将
Intent data = new Intent();
data.putExtra("outputImage", base64ImageString);
setResult(RESULT_OK, data);
finish();
Step3:在App A中,我将使用此代码获取图像详细信息
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==100 && resultCode==RESULT_OK){
String outputImage = data.getStringExtra("base64ImageString");
byte[] decodedString = Base64.decode(outputImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
}
}
但我无法从 App B 到 App A 接收 base64 字符串。它显示以下错误(注意:我可以使用此方法发送普通字符串)
JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1058260)
不接受此答案
在App B中,将图片保存在sd卡中并将图片路径发送给App B,然后在App A中将图片路径转换为base64,然后删除sd卡图片。
【问题讨论】:
-
去掉base64的东西,发回照片JPEG的
byte[]。这仍然需要相当小,但它自然会比 JPEG 的 base64 编码小得多。 -
同意@CommonsWare 观点。请试一试。
-
感谢您的回复。我也试过 byte[] 。但是,我仍然面临同样的问题。 ByteArrayOutputStream 流 = 新的 ByteArrayOutputStream(); outputBitmap.compress(Bitmap.CompressFormat.PNG, 100, 流); byte[] food = stream.toByteArray();
-
如果您想在某些应用程序之间进行交换并且不想将图像存储在光盘上,ContentProvider 可能会有所帮助:stackoverflow.com/questions/29700680/…