我知道为什么OutOfMemoryError异常发生。但有任何最好的方法将字节数组转换为Bitmap.And我使用下面的代码,但是当大字节它强制关闭应用程序并给出OutOfMemoryError异常。Android将字节数组转换为位图的最佳方法?
而我有API它只是返回我的字节数组没有别的。
Bitmap bmp = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);
我知道为什么OutOfMemoryError异常发生。但有任何最好的方法将字节数组转换为Bitmap.And我使用下面的代码,但是当大字节它强制关闭应用程序并给出OutOfMemoryError异常。Android将字节数组转换为位图的最佳方法?
而我有API它只是返回我的字节数组没有别的。
Bitmap bmp = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);
你可能想要使用AQuery库来加载你的图像,这将帮助你调整大小,查看等,并避免最常见的内存泄漏。这个工具可以在这里找到:http://code.google.com/p/android-query/
如何将字节[]转换为位图与AQuery? – atasoyh 2013-05-24 07:30:56
这是什么为我工作: 照片是顺便一个图像的字符串。
byte[] imgbytes = Base64.decode(photo, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(imgbytes, 0,
imgbytes.length);
imageupload.setImageBitmap(bitmap);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapbytes , 0, bitmapbytes .length);
返回解码后的位图,或NULL,如果图像不能解码。
bytearray有多大?真的是一个大的形象?也许图像对于手机内存来说真的很大,如果你从那里检索它,你应该在服务器端压缩它。 – DNax 2013-01-02 21:57:55
结帐这个很好的解释http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – dhams 2014-05-28 06:22:14