出的内存字节分配(位图作为字符串使用肥皂web服务) [英] Out of memory on a byte allocation (Bitmap as String to webservice using soap)

查看:241
本文介绍了出的内存字节分配(位图作为字符串使用肥皂web服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图,所以我要上传webserivceas字符串,并希望以检索字符串。

Am having a bitmap , so I want to upload a webserivceas string and want to retrive the string.

有关转换位为字符串现在用的:

For converting bitmap to string am using:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

strBase64 = Base64.encodeToString(byteArray, Base64.URL_SAFE);

这上面字符串正在使用的属性来soapobject上传。

this above String is using as property to in soapobject to upload.

不过,我得到超出内存在11674900字节分配,而打印和上传。

But am getting Out of memory on a 11674900-byte allocation, while print and uploading.

如果我调试的问题,没有印刷正在逐渐

And if i debugged the issue, without printing am getting

com.sun.jdi.InvocationException occurred invoking method.

SOA prequest。

如何解决这个问题,并上传图片来web服务作为字符串?

How to resolve this issue and to upload image to webservice as string ?

推荐答案

您正在创建一个11MB的图像的3份(位图 strBase64 )。因此,通过调用降低内存占用

You are creating 3 copies of an 11MB image(bitmap, stream, strBase64). So reduce the memory usage by calling

bitmap.recycle();

下面这一行:

below this line:

bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

同样,关闭流,当你用它做(以下 stream.toByteArray(); ):

stream.close();
stream = null;

请记住,有没有保证内存会被这些电话后立即清洗。正确的方式来处理这种情况是块传输大文件块。

Remember that there is no guarantee that memory will be cleaned immediately after these calls. Proper way to handle this type of situation is to transfer large files chunk by chunk.

这篇关于出的内存字节分配(位图作为字符串使用肥皂web服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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