【发布时间】:2016-11-17 10:40:53
【问题描述】:
嗨,我想将位图转换为字节 [] 我这样做了:
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();
接下来我想将此字节 [] 转换为位图,我这样做了:
Bitmap bmp = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
当我检查bmp.getWidth();
并在 Toast 中显示:
Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();
我有空指针,请帮帮我
【问题讨论】:
-
@Community 标记错误。问题是如何防止空位图。不是 NullPointerException 是什么。请撤消。
标签: java android arrays nullpointerexception android-bitmap