2012-03-10 78 views
2

這是我的代碼:
File file = new File(Jpeg File size:700kb);錯誤:位圖大小超過VM預算,將圖像轉換爲ARGB_8888時

InputStream in = null; 

     try { 
    in = new BufferedInputStream(new  FileInputStream(file)); 
    } 
    catch (Exception e) { 
      // TODO: handle exception 
     } 
     bitmap =BitmapFactory.decodeStream(in); 
     bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); 

請您先幫我在這個副本行,我想使其ARGB_8888 image.Need幫助:(

+0

圖像的尺寸是多少? – 2012-03-10 21:21:56

+0

1920x2560宏.. – AsadYarKhan 2012-03-11 04:03:33

+0

我必須要這種形式的圖像ARGB_8888,我正在使用一個tesseract OCR庫,它需要這種形式的位圖圖像,因此它可以OCR圖像.... – AsadYarKhan 2012-03-11 04:05:06

回答

2

得到錯誤您需要減少內存使用情況。

從你的代碼,你一個位圖解碼流,然後複製它,這意味着你創建了兩個大的位圖對象。

你並不需要解碼,然後複製它,你可以嘗試

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPreferredConfig = Bitmap.Config.ARGB_8888 
// You can try value larger than 1 
options.inSampleSize = 2 // If set to a value > 1, requests the decoder to subsample the  original image, returning a smaller image to save memory. 

// Decode bitmap 
bitmap = BitmapFactory.decodeStream(in, null, options) 

在這種情況下,只創建了一個位圖。並且您將inSampleSize設置爲較大的值以減少加載的位圖大小。

+0

偉大的工作男子請同時回覆到我[這](http://stackoverflow.com/questions/9652863/selecting-the-rectangular-area-in-image)發佈以及坦米斯推進 – AsadYarKhan 2012-03-11 10:31:15

相關問題