恩codeD byte64图像导致的OutOfMemoryError机器人 [英] Encoded byte64 image causes OutOfMemoryError android

查看:146
本文介绍了恩codeD byte64图像导致的OutOfMemoryError机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个问题很疯狂:

I'm getting quite crazy with this issue:

我得到一个OutOfMemoryError每次我打开我的应用程序。在某些时候,它从一个服务器loades图像,但它的EN codeDŸ一个Base64字符串。

I am getting an OutOfMemoryError everytime I open my app. At some point, it loades an image from a server, but it's encoded y a Base64 string.

Whay我做的基本上是:

Whay I do is basically:

decodedString = Base64.decode(imagen_codificada);

 Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, 
                            decodedString.length); 

但我发现了那个该死的OOME,每次。

But i'm getting the damned OOME, everytime.

如果想用这样的:

BitmapFactory.Options options=new BitmapFactory.Options();
                        options.inSampleSize = 8;

即使设置选项128,什么是疯狂,但仍然崩溃...

Even setting options to 128, what is crazy, but still crashes...

有减小串进行解码之前以某种方式编纂图像的大小的方法吗?我不能与图像直线运行,因为它使用了许多其他的事情withing应用程序和桌面环境...

Is there a way to reduce the size of the String codifying the image somehow before decoding it? I can't operate straightly with the image, because it's used for many other things withing the app and in desktop environments...

我附上错误日志:

10月12日至21日:36:27.032:E / dalvikvm堆(5508)10119168字节的外部
  分配太大,这一进程。 10月12日至21日:36:27.032:
  E / dalvikvm(5508):内存:堆大小= 5823KB,分配= 4351KB,
  位图大小= 720KB,限值为13692KB 10月12日至21日:36:27.032:E / dalvikvm(5508):
  修剪信息:足迹= 6343KB,允许的足迹= 6343KB,裁剪= 520KB
  10月12日至21日:36:27.032:E / GraphicsJNI(5508):虚拟机不会让我们分配
  10119168字节10月12日至21日:36:27.192:E / AndroidRuntime(5508):FATAL
  例外:主要十月12日至21日:36:27.192:E / AndroidRuntime(5508):
  java.lang.OutOfMemoryError:位图的大小超过VM预算

12-21 10:36:27.032: E/dalvikvm-heap(5508): 10119168-byte external allocation too large for this process. 12-21 10:36:27.032: E/dalvikvm(5508): Out of memory: Heap Size=5823KB, Allocated=4351KB, Bitmap Size=720KB, Limit=13692KB 12-21 10:36:27.032: E/dalvikvm(5508): Trim info: Footprint=6343KB, Allowed Footprint=6343KB, Trimmed=520KB 12-21 10:36:27.032: E/GraphicsJNI(5508): VM won't let us allocate 10119168 bytes 12-21 10:36:27.192: E/AndroidRuntime(5508): FATAL EXCEPTION: main 12-21 10:36:27.192: E/AndroidRuntime(5508): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

编辑:与此解决:

decodedString = Base64.decode(imagen_codificada);
                    System.gc();
                    BitmapFactory.Options options=new BitmapFactory.Options();
                    options.inSampleSize = 8;
                    InputStream input = new ByteArrayInputStream(decodedString);
                    Bitmap decodedByte = BitmapFactory.decodeStream(input, null, 
                            options); 
                    menu.setNombreApellido(decodedByte);

谢谢大家!

推荐答案

试试这个结果字节[]德codedString =(字节[])Base64.de code( imagen_codificada); 结果
这将直接返回U位阵列。现在ü可以使用结果
BitmapFactory.Options选项=新BitmapFactory.Options(); //
 options.inSampleSize = 8;

按比例缩小你的照片。

try this
byte[] decodedString = (byte[])Base64.decode(imagen_codificada);
This will return u bit array directly . Now u can use
BitmapFactory.Options options=new BitmapFactory.Options(); // options.inSampleSize = 8; to scale down your photograph .

这篇关于恩codeD byte64图像导致的OutOfMemoryError机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆