사진을 찍은 다음 앱에 표시하는 앱이 있습니다. 촬영 한 첫 번째 이미지가 작동하고 앱에 표시되지만 두 번째 이미지를 촬영하면 앱이 다운되고 logcat의 제목에 오류가 표시됩니다.이미지를 표시하면 메모리 오류가 발생합니다 (31961104 바이트 할당시 메모리가 부족합니다).
p.s 친구가 작성한 코드이므로 100 % 확실하지 않습니다.
코드
private PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
mImageView = (ImageView) findViewById(R.id.mImageView);
Bitmap imageBitmap = BitmapFactory.decodeByteArray(data, 0,
data.length);
mImageView.setImageBitmap(imageBitmap);
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
/*
* Log.d(TAG,
* "Error creating media file, check storage permissions: " +
* e.getMessage());
*/
return;
}
try {
SharedPreferences save = getPreferences(0);
SharedPreferences.Editor editor = save.edit();
editor.putString("oldFile", pictureFile.getAbsolutePath());
// Commit the edits!
editor.commit();
Log.v("output", "oldFile: " + oldFilePath);
File oldFile = new File(oldFilePath);
if(oldFile.delete()) // DELETING PICTURES TOO FAST.
Log.v(TAG, "Image deleted.");
oldFilePath = pictureFile.getAbsolutePath();
Log.v("output", "newFile: " + oldFilePath);
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
로그 캣
02-19 14 : 22 : 08.158 : E/dalvikvm 힙 (10,394) 메모리 가운데 31,961,104 바이트에 할당. 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : 치명적인 예외 : 주 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : java.lang.OutOfMemoryError 02-19 14:22 : 08.163 : E/AndroidRuntime (10394) : android.graphics.BitmapFactory.nativeDecodeByteArray (기본 메소드) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : android.graphics.BitmapFactory.decodeByteArray (BitmapFactory. 자바 : 551) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : android.graphics.BitmapFactory.decodeByteArray (BitmapFactory.java:569) 02-19 14 : 22 : 08.163 : E/AndroidRuntime 10394) : com.example.oxplastics.MainActivity $ 1.onPictureTaken (MainActivity.java:331) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : android.hardware.Camera $ EventHandler.handleMessage (카메라 .java : 823) 02-19 14:22 : 08.163 : E/AndroidRuntime (10394) : android.os.Handler.dispatchMessage (Handler.java:99) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : android.os.Looper.loop (Looper.java:137) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : android.app.ActivityThread.main (ActivityThread.java:4921) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : java.lang.reflect.Method.invokeNative (네이티브 메소드) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : java.lang.reflect.Method.invoke (Method. java : 511) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1027) 02-19 14:22 : 08 : 63 : E/AndroidRuntime (10394) : com.android.internal.os.ZygoteInit.main (ZygoteInit.java:794) 02-19 14 : 22 : 08.163 : E/AndroidRuntime (10394) : at dalvik.sy stem.NativeStart.main (기본 방법)
귀하의 logcat 게시 !! – r4jiv007
또한 코드를 게시하십시오! – Behnam
맙소사, 사람들이 다른 질문을보고 비트 맵과 관련된 OOM 게시를 중단하기 전에이 질문을 몇 번이나 반복해야합니까? – 2Dee