Android out of memory on image capture

前端 未结 2 1381
春和景丽
春和景丽 2020-12-31 20:01

I have an Activity which takes photos (with full possible resolution, so quite large), the application have then the chance to analyze them. Only one photo is handled at a t

2条回答
  •  感情败类
    2020-12-31 20:37

    Since you run out of memory after 4-5 pictures you probably arent calling yourBitmap.recycle(); after it has been saved to the SD-card?

    Also in the onPictureTaken() method you could save the tempData from the picture into a bitmap using the Bitmap.Config.RGB_565 instead of ARGB(default) if you don't need the alpha channel.

       // Create options to help use less memory   
        Options opt = new Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
    
       // Decode the tempdata into a bitmap, with the options as the last argument 
        bitmapFromRawCameraTempData = BitmapFactory.decodeByteArray(rawCameraTempData, 0, rawCameraTempData.length, opt);
    

提交回复
热议问题