在我的Android应用程序中我从相机拍摄图像,然后我想编码它而不压缩。然后编码后我想解码并在图像视图中显示
以下是代码,压缩并且工作正常(图像显示在图像视图中)
Bitmap thumbnail;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.PNG, 1, bytes);
byte[] b = bytes.toByteArray();
String ImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(ImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,bytarray.length);
imageView11.setImageBitmap(bmimage);
但是当我在imageView中使用以下代码图片时不显示。请帮助
int bytes = b.getWidth()*b.getHeight()*4;
ByteBuffer buffer = ByteBuffer.allocate(bytes);
thumbnail.copyPixelsToBuffer(buffer);
byte[] b = buffer.array();
String ImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(ImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,bytarray.length);
imageView11.setImageBitmap(bmimage);