【发布时间】:2011-07-24 17:05:50
【问题描述】:
这让我有点生气!
我已经拍摄了一张图片,并使用 Bitmap.Compress 方法将图片放入一个字节数组中(如下)
InputStream is = MyActivity.this.getContentResolver().openInputStream(imageUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2; //try to decrease decoded image
options.inPurgeable = true; //purgeable to disk
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, bos);
myModel.setFullImage(bos.toByteArray());
但是,当我查看 byte[] 的前几个字节时,它包含许多 -1 以及有效数字 (0-255) 和负数,如 -98 等。
然后我通过网络发送此数据(以 json 格式),但由于数组中的负数,它无法将其转换为 c# byte[]。
出了什么问题或者我错过了什么。我什至尝试将压缩因子设置为 0,以防压缩正在执行某些操作。
奇怪的是,如果我将字节转换为 base64 然后传输,我可以成功地将 base64 字符串转换为 c# 中的 byte[] 以保存图像。
怎么了?
提前致谢
乔恩
【问题讨论】:
标签: c# java android json bytearray