Java android 将图像转换为 byte[] 而不压缩并将 byte[] 转换为 img
Java android convert image to byte [] without compress and convert byte[] to img
您好,我想将位图转换为字节[] 我这样做了:
byte[] imageInByte;
Uri uri = data.getData();
bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
} catch (IOException e) {
e.printStackTrace();
}
int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
imageInByte = byteBuffer.array();
接下来我想将这个 byte[] 转换为位图,我这样做了 :
Bitmap bmp = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
当我检查 bmp.getWidth();
并在 Toast 中显示:
Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();
我有空指针请帮助我
copyPixelsToBuffer()
的反转不是 decodeByteArray()
而是 copyPixelsFromBuffer()
。
您好,我想将位图转换为字节[] 我这样做了:
byte[] imageInByte;
Uri uri = data.getData();
bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
} catch (IOException e) {
e.printStackTrace();
}
int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
imageInByte = byteBuffer.array();
接下来我想将这个 byte[] 转换为位图,我这样做了 :
Bitmap bmp = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
当我检查 bmp.getWidth();
并在 Toast 中显示:
Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();
我有空指针请帮助我
copyPixelsToBuffer()
的反转不是 decodeByteArray()
而是 copyPixelsFromBuffer()
。