2017-07-15 53 views
0

我試圖保存在FrameProcessor.Delegate.onFrameProcessed上收到的幀。runOnUiThread和Flir One SDK發生OutOfMemory錯誤

如果我嘗試使用runOnUiThread使用renderedImage.getFrame().save(...)線程內,我得到以下異常:

AndroidRuntime: Error reporting crash 
java.lang.OutOfMemoryError: Failed to allocate a 25235166 byte allocation with 16777216 free bytes and 20MB until OOM 
    at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95) 
    at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:125) 
    at java.lang.StringBuffer.append(StringBuffer.java:278) 
    at java.io.StringWriter.write(StringWriter.java:123) 
    at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:358) 
    at com.android.internal.util.FastPrintWriter.appendLocked(FastPrintWriter.java:303) 
    at com.android.internal.util.FastPrintWriter.write(FastPrintWriter.java:625) 
    at com.android.internal.util.FastPrintWriter.append(FastPrintWriter.java:658) 
    at java.io.PrintWriter.append(PrintWriter.java:691) 
    at java.io.PrintWriter.append(PrintWriter.java:687) 
    at java.io.Writer.append(Writer.java:198) 
    at java.lang.Throwable.printStackTrace(Throwable.java:324) 
    at java.lang.Throwable.printStackTrace(Throwable.java:300) 
    at android.util.Log.getStackTraceString(Log.java:527) 
    at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:61) 
    at com.android.internal.os.RuntimeInit.-wrap0(RuntimeInit.java) 
    at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:86) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 

這是做原來的線程的方法:

private FrameProcessor.Delegate frameProcessorDelegate = new FrameProcessor.Delegate() { 
    @Override 
    public void onFrameProcessed(final RenderedImage renderedImage) { 
     //Capture this image if requested 
     if (imageCaptureRequested) { 
      imageCaptureRequested = false; 
      setProgressVisibility(VISIBLE); 

      new Thread(new Runnable() { 
       public void run() { 
        String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); 
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd-HHmmss", Locale.getDefault()); 
        String formatedDate = sdf.format(new Date()); 
        String fileName = formatedDate + ".jpg"; 
        try { 
         lastSavedPath = path + "/" + fileName; 

         renderedImage.getFrame().save(new File(lastSavedPath), RenderedImage.Palette.Iron, RenderedImage.ImageType.BlendedMSXRGBA8888Image); 

         toggleConfirmPhotoScreen(true, lastSavedPath); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 
      }).start(); 
     } 
    } 
}; 

的方法使用runOnUiThread:

private void toggleConfirmPhotoScreen(final boolean show, final String lastSavedPath) { 
    //works until here 
    Log.d("ExampleApp", "toggleConfirmPhotoScreen"); 
    ((Activity) getContext()).runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      //NEVER REACHES HERE 
      Log.d("ExampleApp", "  " + show + " CancelConfirmScreen"); 
     } 
    }); 
} 

因爲你可以se e在代碼中的評論中,toggleConfirmPhotoScreen被調用,但runOnUiThread裏面什麼也沒有,當我想到OutOfMemoryException發生時。

回答

0

把你的清單
機器人:largeHeap = 「真」

+0

沒有工作....但感謝! – RominaV