拍摄超过13张照片时出现OutOfMemoryError

时间:2018-05-13 18:53:03

标签: android out-of-memory android-camera

当我拍摄超过13张图片时,我出现了OutOfMemoryError。它重新启动后崩溃它允许我拍摄另外13张图片

我在崩溃后重新启动应用程序。

这里是我的StactTrace

PID: 9656                                                            
java.lang.OutOfMemoryError: (Heap Size=259476KB, Allocated=246686KB)                                                                                
at android.graphics.Bitmap.nativeCreate(Native Method)                                                                           
at android.graphics.Bitmap.createBitmap(Bitmap.java:1137)                                                                                  
at android.graphics.Bitmap.createBitmap(Bitmap.java:1109)                                                                                 
at android.graphics.Bitmap.createBitmap(Bitmap.java:1076)                                                                                
at 
com.redmonk.bricapp.enterprise.cameramodule.control.CameraPreview.
initFocusDrawingTools(CameraPreview.java:114)                                                                                 
at 
com.redmonk.bricapp.enterprise.cameramodule.control.CameraPreview.
surfaceChanged(CameraPreview.java:139)                                                                                  
at android.view.SurfaceView.updateWindow(SurfaceView.java:583)                                                                                  
at android.view.SurfaceView.access$000(SurfaceView.java:86)                                                                                  
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)                                                                                  
at 
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)                                                                                  
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1993)                                                                                  
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1076)                                                                                  
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5905)                                                                                  
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:807)                                                                                  
at android.view.Choreographer.doCallbacks(Choreographer.java:601)                                                                                  
at android.view.Choreographer.doFrame(Choreographer.java:562)                                                                                  
at 
android.view.Choreographer$FrameDisplayEventReceiver.run
(Choreographer.java:791                                                                                  
at android.os.Handler.handleCallback(Handler.java:733)                                                                                  
at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                  
at android.os.Looper.loop(Looper.java:157)                                                                                  
at android.app.ActivityThread.main(ActivityThread.java:5633)                                                                                  
at java.lang.reflect.Method.invokeNative(Native Method)                                                                                  
at java.lang.reflect.Method.invoke(Method.java:515)                                                                                  
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:896)                                                                                 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)                                                                                  
at dalvik.system.NativeStart.main(Native Method)  

我遇到异常的方法我在崩溃后重新启动应用程序

private void focused() {
focusing = false;
String checkBeep =  Prefs.getString("BeepDone","");
try {
if (!checkBeep.equals("true")) {
    MediaPlayer mPlayer2, mMediaPlayer;
mMediaPlayer = new MediaPlayer();
mMediaPlayer = 
MediaPlayer.create(WebServiceSingleTon.getInstance().mainActivity,R.raw.
beepnew);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setVolume(1, 1);
mMediaPlayer.setLooping(false);
mMediaPlayer.start();
Prefs.putString("BeepDone", "true");
}
if (focusCallback != null) {
    focusCallback.onFocused(camera);
}
}catch (OutOfMemoryError e)
{
e.printStackTrace();
cp.initiateSmoothRestart();// I am restarting app Here
}catch (Exception e)
{
e.printStackTrace();
}
}

项目范围的Gradle设置。

# IDE (e.g. Android Studio) users:
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m - 
XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# org.gradle.parallel=true
android.useDeprecatedNdk=true

1 个答案:

答案 0 :(得分:0)

如果要将图像保存在RAM中,请尝试使用缩放位图。 这对我有用:

Copy