0

Androidで写真処理アプリを作ろうとしています。srcファイルから写真を読み込もうとすると、OutOfMemoryErrorが返されました

使ってみました

Bitmap.createBitmap(src.width, src.height, src.getConfig());

入力写真は29KBの普通の写真ですが、これも試してみました

画像をビットマップオブジェクトにロードする際のメモリ不足の問題

しかし、結果は同じです、誰かがこれの何が問題なのか教えてもらえますか?私は完全に考えがわからない...

使用したコードの一部

ImageView image, processedImage;
Bitmap bitmapImage;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image = (ImageView)findViewById(R.id.testingImage);
    processedImage = (ImageView)findViewById(R.id.prcoessedImage);

    InputStream is = this.getResources().openRawResource(R.drawable.testingimage);

    bitmapImage = BitmapFactory.decodeStream(is);
    imageProcessing(bitmapImage);
}

public static Bitmap imageProcessing(Bitmap src) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());
    ...
}

logcat

08-31 15:50:54.694: D/ddm-heap(5497): Got feature list request
08-31 15:50:54.842: D/dalvikvm(5497): Trying to load lib lib_glossary.so 0x0
08-31 15:50:54.842: I/dalvikvm(5497): Unable to dlopen(lib_glossary.so): Cannot load library: load_library[1051]: Library 'lib_glossary.so' not found
08-31 15:50:54.842: E/MBGlossaryManager(5497): lib_glossary.so can't be loaded
08-31 15:50:55.178: D/dalvikvm(5497): GC freed 699 objects / 54432 bytes in 300ms
08-31 15:50:56.671: D/dalvikvm(5497): GC freed 65 objects / 2600 bytes in 230ms
08-31 15:50:59.374: D/dalvikvm(5497): GC freed 178 objects / 7992 bytes in 36ms
08-31 15:50:59.374: E/dalvikvm-heap(5497): 6432832-byte external allocation too large for this process.
08-31 15:50:59.374: E/(5497): VM won't let us allocate 6432832 bytes
08-31 15:50:59.374: D/AndroidRuntime(5497): Shutting down VM
08-31 15:50:59.374: W/dalvikvm(5497): threadid=3: thread exiting with uncaught exception (group=0x4001e2e0)
08-31 15:50:59.374: E/AndroidRuntime(5497): Uncaught handler: thread main exiting due to uncaught exception
08-31 15:50:59.374: E/AndroidRuntime(5497): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.graphics.Bitmap.nativeCreate(Native Method)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.graphics.Bitmap.createBitmap(Bitmap.java:494)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.graphics.Bitmap.createBitmap(Bitmap.java:461)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:366)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at com.image.process.MainActivity.onCreate(MainActivity.java:42)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2574)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.ActivityThread.access$2400(ActivityThread.java:121)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1925)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.os.Looper.loop(Looper.java:136)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at android.app.ActivityThread.main(ActivityThread.java:4425)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at java.lang.reflect.Method.invokeNative(Native Method)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at java.lang.reflect.Method.invoke(Method.java:521)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
08-31 15:50:59.374: E/AndroidRuntime(5497):     at dalvik.system.NativeStart.main(Native Method)
08-31 15:50:59.397: I/dalvikvm(5497): threadid=7: reacting to signal 3
08-31 15:50:59.397: I/dalvikvm(5497): Wrote stack trace to '/data/anr/traces.txt'
4

1 に答える 1

2
Bitmap bitmap = Bitmap.createScaledBitmap(bitmapImage , bitmapImage.getWidth(),  bitmapImage.getHeight(), null);

processedImage.setImageBitmap(bitmap);
于 2012-08-31T07:11:12.337 に答える