/** * 根据图像URL创建Bitmap * * @param url URL地址 * @return bitmap */ public Bitmap CreateImage(String url) { // Logger.d("ImageDownloader", // "开始调用CreateImage():" + System.currentTimeMillis()); Bitmap bitmap = null; if (url == null || url.equals("")) { return null; } try { // Logger.d( // "ImageDownloader", // "C Before SDCard decodeStream==>" + "Heap:" // + (Debug.getNativeHeapSize() / 1024) + "KB " // + "FreeHeap:" // + (Debug.getNativeHeapFreeSize() / 1024) + "KB " // + "AllocatedHeap:" // + (Debug.getNativeHeapAllocatedSize() / 1024) // + "KB" + " url:" + url); FileInputStream fis = new FileInputStream(url); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_4444; opts.inTempStorage = new byte[100 * 1024]; opts.inPurgeable = true; opts.inInputShareable = true; bitmap = BitmapFactory.decodeStream(fis, null, opts); // Logger.d( // "ImageDownloader", // "C After SDCard decodeStream==>" + "Heap:" // + (Debug.getNativeHeapSize() / 1024) + "KB " // + "FreeHeap:" // + (Debug.getNativeHeapFreeSize() / 1024) + "KB " // + "AllocatedHeap:" // + (Debug.getNativeHeapAllocatedSize() / 1024) // + "KB" + " url:" + url); } catch (OutOfMemoryError e) { LogUtils.e("OutOfMemoryError", e); System.gc(); } catch (FileNotFoundException e) { LogUtils.e("FileNotFoundException", e); } // Logger.d("ImageDownloader", // "结束调用CreateImage():" + System.currentTimeMillis()); return bitmap; }
// Recycle the resource of the Image public void recycleImage(Bitmap bitmap) { try { if (bitmap != null && !bitmap.isMutable() && !bitmap.isRecycled()) { bitmap.recycle(); System.gc(); } } catch (Exception e) { e.printStackTrace(); LogUtils.e("bitmap recycle excpetion", e); } }