Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android在不压缩的情况下将图像转换为字节[],并将字节[]转换为img_Java_Android_Arrays_Nullpointerexception_Android Bitmap - Fatal编程技术网

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);
当我检查a
bmp.getWidth()时
并以祝酒辞表示:

Toast.makeText(this,bmp.getWidth()+"",Toast.LENGTH_SHORT).show();

我有空指针,请帮我copyPixelsToBuffer()
的反面不是
DecodeBytarray()
,而是
copyPixelsFromBuffer()

@社区错误标记。问题是如何防止空位图。不是NullPointerException是什么。请撤消。