Java android在不压缩的情况下将图像转换为字节[],并将字节[]转换为img
您好,我想将位图转换为字节[]我执行了以下操作:Java android在不压缩的情况下将图像转换为字节[],并将字节[]转换为img,java,android,arrays,nullpointerexception,android-bitmap,Java,Android,Arrays,Nullpointerexception,Android Bitmap,您好,我想将位图转换为字节[]我执行了以下操作: byte[] imageInByte; Uri uri = data.getData(); bitmap = null; try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); } catch (IOException e) { e.printStackTrace(); } int size = bitmap.getRowBy
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);
当我检查abmp.getWidth()时代码>
并以祝酒辞表示:
Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();
我有空指针,请帮我copyPixelsToBuffer()
的反面不是DecodeBytarray()
,而是copyPixelsFromBuffer()
@社区错误标记。问题是如何防止空位图。不是NullPointerException是什么。请撤消。