您好我想将Bitmap转换为byte []我这样做了:
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,我这样做了:
Bitmap bmp = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
当我检查bmp.getWidth();
时
并在Toast中显示:
Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();
我有nullpointer请帮帮我
答案 0 :(得分:2)
copyPixelsToBuffer()
的反面不是{{1}},而是decodeByteArray()
。