2011-08-28 49 views
1

我開發一個應用程序,顯示大圖像..有大量的圖像大小在700x8100左右..我可以創建一個EncodedImage類型的對象,而不會拋出異常,但是當我嘗試執行getBitmap我收到一個OutOfMemory錯誤。 這是發生異常的行:Blackberry - OutOfMemory當處理大圖像

Bitmap imgBtm = encodedImagePng.getBitmap(); 

有什麼樣的分辨率大小的限制?

有沒有人已經不得不處理大圖片?

任何幫助將是非常有用的..

韓國社交協會

回答

1

您必須在使用getBitmap()函數之前調整編碼圖像的大小。首先構建你的EncodedImage,然後使用重新調整了下列文件:

private static EncodedImage rescaleEncodedImage (EncodedImage image, int width, int height) { 
     EncodedImage result = null; 
     try { 
      int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); 
      int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); 
      int requiredWidthFixed32 = Fixed32.toFP(width); 
      int requiredHeightFixed32 = Fixed32.toFP(height); 
      int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32); 
      int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32); 
      result = image.scaleImage32(scaleXFixed32, scaleYFixed32); 
     } 
     catch (Exception ex) { 

     } 
     return result; 
    } 

然後調整從它

得到位圖後
0

您無法讀取如此大到設備內存中的圖像。有一些內置的方法可以在縮小圖像的同時解碼圖像,從而避免將原始圖像加載到內存中。在獲取位圖之前,嘗試使用EncodedImage.scaleImage32來設置更合理的維度。