我制作了一个图像查看器项目,TouchImageView
用于实现缩放、拖放、全景查看器等。
查看器工作正常,除了OutOfMemory
旋转设备时出现错误,特别是全景图(不是很大,3.5 MB 应该很容易被 Galaxy Note 处理)。这是违规行:
final Bitmap myBitmap = BitmapFactory.decodeFile(filename);
当然,因为它是全景图,所以我想缩放,所以在解码时压缩图像,如此处所建议的,不是一种选择(我已经尝试过,并且有效,但是低质量扼杀了全景图的想法)。
我认为我的项目中没有内存泄漏,因为它不是内存密集型的,只会在旋转时冻结,并且违规行仅在旋转时执行一次。我可以看到全景在屏幕上对角线冻结。我认为问题在于 ImageView 的“旋转动画”。也许我应该禁用它?如果是这样,怎么做?
下面是崩溃日志。
谢谢!!
日志-
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)