2013-03-28 66 views

回答

1

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

鏈接引導你如何加載位圖有效especialcy下負載縮小版的話題到內存

在不使用時,您應該回收的位圖。

   bitmaps.recycle(); 

位圖也存儲在從honeycomb開始的堆上。所以當不使用時回收位圖。

http://www.youtube.com/watch?v=_CruQY55HOk。如果遇到內存泄漏,請使用MAT分析器來查找並修復它。該視頻就這個話題進行了討論。它還解釋瞭如何管理內存。

如果要顯示大量的位圖,請使用通用圖像加載程序。使用listview或grdiview來顯示圖像。

https://github.com/nostra13/Android-Universal-Image-Loader

它基於Lazy List(基於相同原理)。但它有很多其他配置。我寧願使用通用圖像加載程序因爲它給你更多的配置選項。如果downlaod失敗,您可以顯示錯誤圖像。可以顯示圓角的圖像。可以緩存在光盤或內存上。可以壓縮圖像。

在您的自定義適配器構造

File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder"); 

// Get singletone instance of ImageLoader 
imageLoader = ImageLoader.getInstance(); 
// Create configuration for ImageLoader (all options are optional) 
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a) 
     // You can pass your own memory cache implementation 
    .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation 
    .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) 
    .enableLogging() 
    .build(); 
// Initialize ImageLoader with created configuration. Do it once. 
imageLoader.init(config); 
    options = new DisplayImageOptions.Builder() 
    .showStubImage(R.drawable.stub_id)//display stub image 
    .cacheInMemory() 
    .cacheOnDisc() 
    .displayer(new RoundedBitmapDisplayer(20)) 
    .build(); 

在你getView()

ImageView image=(ImageView)vi.findViewById(R.id.imageview); 
    imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options. 

你可以用其他選項配置,以滿足您的需求。

隨着延遲加載/通用圖像加載器,您可以查看持有人的平滑滾動和性能。 http://developer.android.com/training/improving-layouts/smooth-scrolling.html

+0

謝謝..但根據我的要求,我不想縮小圖像。我正在做一個圖像stegnography應用程序。我從廚房獲取圖像並隱藏其中的文本。雖然獲取'3215 * 1525'內存問題的圖像維度存在...所以在我的情況下,我想隱藏從我的應用程序中獲取的庫中的大尺寸圖像。 – AbiAndroid 2013-03-28 06:50:36

+0

您是否顯示大量圖像?在那種情況下使用UIL。如果其他人可以提出建議,我期待着一種替代解決方案。爲了更好地理解你應該看看提到的鏈接。 – Raghunandan 2013-03-28 06:52:43

+0

http://stackoverflow.com/questions/3331527/android-resize-a-large-bitmap-file-to-scaled-output-file。我很好奇,看看另一種解決方案 – Raghunandan 2013-03-28 06:57:12