android有效解决加载大图片时内存溢出的问题,Android有效解决加载大图片时内存溢出的问题(国外英文资料).doc...

Android有效解决加载大图片时内存溢出的问题(国外英文资料)

Android有效解决加载大图片时内存溢出的问题(国外英文资料)

Android effectively solves the problem of memory leaks when loading large images

Blog classification: Android

Android game virtual machine algorithm JNI

Try not to use setImageBitmap or setImageResource or bitmapfactors.decoderesource to set up a large image,

Because these functions are finished by decode, they end up using the createBitmap of the Java layer, which consumes more memory.

So, instead of using bitmapfactor.decodestream, we created a bitmap, and then we set it to the source of the ImageView,

The biggest secret of decodeStream is its direct call to JNI > > nativeDecodeAsset () to complete decode,

There is no need to use the createBitmap of the Java layer to save the Java layer space.

If you add the Config parameter to the image at the time of reading, you can effectively reduce the amount of Memory that is loaded in order to effectively block out the out of Memory exception

In addition, the decodeStream takes the image directly to read the bytecode and does not automatically adapt to the various resolutions of the machine,

After using the decodeStream, you need to configure the corresponding image resources in the hdpi and the mdpi, ldpi,

Otherwise, it's the same size on different resolution machines (the number of pixels), and the size of the display is incorrect.

In addition, the following ways are also helpful:

1.inputstream is this.getresources (R.d rawable.

Bitmapfactor.options Options = new bitmapfactor.options ()

Options. InJustDecodeBounds = false;

Options. InSampleSize = 10; / / width, hight is the original one

Bitmap BTP = bitmapfactory.decodestream (is, null, options);

If (!)

The memory used by the BMP. Recycle ()/recycle image

The system.gc () / / warning system is recovered in time

}

Here's a way:

Java code

/ * * 1.

* read pictures of local resources in the most convenient way

* @param context

* @param resId

* @return

6. * /

The public static Bitmap readBitMap (Context Context, int resId)

8 bitmapfactor.optio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值