Android将字节数组转换为Bitmap的最佳方法?

Pat*_*yur 10 java android byte

我知道为什么会出现OutOfMemoryError异常.但是有任何最好的方法将字节数组转换为Bitmap.And我使用下面的代码,但是当大字节时它强制关闭app并给出OutOfMemoryError Exception.

我有API它只是返回字节数组没有别的.

Bitmap bmp = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);
Run Code Online (Sandbox Code Playgroud)

Xar*_*mer 7

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapbytes , 0, bitmapbytes .length);
Run Code Online (Sandbox Code Playgroud)

返回已解码的位图,如果图像无法解码,则返回null.


AMe*_*rle 0

您可能必须使用以下方法(DOC,相同的方法,但带有 options 参数):

public static Bitmap decodeByteArray (byte[] data, int offset, int length, BitmapFactory.Options opts)
Run Code Online (Sandbox Code Playgroud)

并使用选项参数。希望这对你有帮助 =)