I made an image viewer project with a TouchImageView
to implement zoom, drag and fling, a panorama viewer, etc.
The viewer works fine, except that I get OutOfMemory
errors when rotating the device, specially for panoramas (not really big, 3.5 MB should be easily handled by a Galaxy Note). This is the offending line:
final Bitmap myBitmap = BitmapFactory.decodeFile(filename);
Of course, since it is a panorama, I want to zoom, so compressing the image at decoding time, as suggested here, is not an option (I've tried it, and works, but the low quality kills the idea of a panorama).
I don't think there's a memory leak in my project, since it is not memory intensive, only freezes at rotation, and the offending line is executed only once at rotation. I can see the panorama freezing diagonally in the screen. I think the problem is the "rotation animation" of the ImageView. Maybe I should disable it? If so, how?
Below is the crash log.
Thanks!!
LOG-
58:38.845: W/dalvikvm(2465): threadid=1: thread exiting with uncaught exception (group=0x40c531f8)
12-24 02:58:38.850: E/AndroidRuntime(2465): FATAL EXCEPTION: main
12-24 02:58:38.850: E/AndroidRuntime(2465): java.lang.OutOfMemoryError
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:418)
12-24 02:58:38.850: E/AndroidRuntime(2465): at com.floritfoto.apps.xvf.Foto.pic(Foto.java:180)
12-24 02:58:38.850: E/AndroidRuntime(2465): at com.floritfoto.apps.xvf.Foto.onCreate(Foto.java:383)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.Activity.performCreate(Activity.java:4465)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3363)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread.access$700(ActivityThread.java:127)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.os.Handler.dispatchMessage(Handler.java:99)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.os.Looper.loop(Looper.java:137)
12-24 02:58:38.850: E/AndroidRuntime(2465): at android.app.ActivityThread.main(ActivityThread.java:4507)
12-24 02:58:38.850: E/AndroidRuntime(2465): at java.lang.reflect.Method.invokeNative(Native Method)
12-24 02:58:38.850: E/AndroidRuntime(2465): at java.lang.reflect.Method.invoke(Method.java:511)
12-24 02:58:38.850: E/AndroidRuntime(2465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
12-24 02:58:38.850: E/AndroidRuntime(2465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
12-24 02:58:38.850: E/AndroidRuntime(2465): at dalvik.system.NativeStart.main(Native Method)