在Android的位图处理与单机器人/ xamarin.android最佳practis [英] Best practis for handling bitmaps in android with mono droid / xamarin.android

查看:179
本文介绍了在Android的位图处理与单机器人/ xamarin.android最佳practis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理位图时具有Android应用一些内存问题(废话!)。

I am having some memory issues with our android app when handling bitmaps (duh!).

我们都具有多个活动从一台服务器加载图像,这可能是为活动的背景图像。
此背景图像可以是对多个活动是相同的,而现在每个活动加载其自己的背景图像。
这意味着如果流是ac1-> ac2-> ac3-> AC4相同的图像将被加载4次,并使用4倍存储器

We are having multiple activities loading images from a server, this could be a background image for the activity. This background image could be the same for multiple activities, and right now each activity is loading its own background image. This means if the flow is ac1->ac2->ac3->ac4 the same image will be loaded 4 times and using 4x memory.

我如何优化imagehandling对于这种情况?我是否创建该映像的存储,然后每个活动先问缓存图像的图像缓存。如果是这样的话,我怎么知道什么时候垃圾从缓存中收集的形象呢?

How do I optimize imagehandling for this scenario? Do I create an image cache where the image is stored and then each activity ask the cache first for images. If this is the case, how do I know when to garbage collect the image from the cache?

任何建议,链接到好的教程或类似的高度AP preciated。

Any suggestions, link to good tutorials or similar is highly appreciated.

问候

编辑:
当下载图像设备的确切尺寸时,这意味着如果UI元素需要一个100×100象素图象它得到该尺寸和因此不需要缩放。所以我不知道加载到内存时缩减图像。也许它是需要在活动中卸载图像的下一个移动,然后回去时重新加载时。

When downloading images for the device the exact sizes is used, meaning that if the ui element needs an 100x100 pixel image it gets that size and therefore no need for scaling. So i am not sure about downscaling the image when loading it into the memory. Maybe it is needed to unload images in the activity when moving on the the next and then reload when going back.

推荐答案

准备您的更新后,我会给你一个提示其他然后。
我仍然可以发布补丁太多,如果人们想要的..

After ready your update I will give you an other tip then. I can still post the patch too if people want that..

您需要的位图做的是给他们打电话了使用块。这样,Android将尽快执行该块卸载位。

What you need to do with those bitmaps is call them with a using block. That way Android will unload the bitmap as soon as that block is executed.

例如:

using(Bitmap usedBitmap = new Bitmap()){
     //Do stuff with the Bitmap here
     //You can call usedBitmap.Dispose() but it's not really needed
}

有了这个code您的应用程序不应该把所有的使用的位图在内存中。

With this code your app shouldn't keep all the used bitmaps in memory.

这篇关于在Android的位图处理与单机器人/ xamarin.android最佳practis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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