我遇到java.lang.outOfMemoryError
的问题。我想这是因为加载图像,因为其他东西不会占用大量内存。
这是我用来调整图像大小的方法
public class ImageLoader {
public void setPic(Resources res, int id, ImageView destination) {
int targetW = destination.getWidth();
int targetH = destination.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, id, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeResource(res, id, bmOptions);
destination.setImageBitmap(bitmap);
}
}
这是LogCat堆栈。
05-19 16:21:35.820: D/dalvikvm(5577): GC_FOR_ALLOC freed 5786K, 12% free 106971K/121220K, paused 29ms, total 30ms
05-19 16:21:35.820: I/dalvikvm-heap(5577): Forcing collection of SoftReferences for 85047208-byte allocation
05-19 16:21:35.850: D/dalvikvm(5577): GC_BEFORE_OOM freed 74K, 12% free 106896K/121220K, paused 34ms, total 34ms
05-19 16:21:35.850: E/dalvikvm-heap(5577): Out of memory on a 85047208-byte allocation.
05-19 16:21:35.850: I/dalvikvm(5577): "main" prio=5 tid=1 RUNNABLE
05-19 16:21:35.850: I/dalvikvm(5577): | group="main" sCount=0 dsCount=0 obj=0x41ee8ca8 self=0x41ed73c8
05-19 16:21:35.850: I/dalvikvm(5577): | sysTid=5577 nice=0 sched=0/0 cgrp=apps handle=1074188628
05-19 16:21:35.850: I/dalvikvm(5577): | state=R schedstat=( 20424785767 7445835959 68847 ) utm=1573 stm=469 core=0
05-19 16:21:35.850: I/dalvikvm(5577): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-19 16:21:35.850: I/dalvikvm(5577): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
05-19 16:21:35.850: I/dalvikvm(5577): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
05-19 16:21:35.850: I/dalvikvm(5577): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:445)
05-19 16:21:35.850: I/dalvikvm(5577): at com.guesstheyear.model.ImageLoader2.setPic(ImageLoader2.java:33)
05-19 16:21:35.850: I/dalvikvm(5577): at com.guesstheyear.activities.GameActivity.onWindowFocusChanged(GameActivity.java:155)
05-19 16:21:35.850: I/dalvikvm(5577): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2647)
05-19 16:21:35.850: I/dalvikvm(5577): at android.view.View.dispatchWindowFocusChanged(View.java:7900)
05-19 16:21:35.860: I/dalvikvm(5577): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
05-19 16:21:35.860: I/dalvikvm(5577): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3140)
05-19 16:21:35.860: I/dalvikvm(5577): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 16:21:35.860: I/dalvikvm(5577): at android.os.Looper.loop(Looper.java:136)
05-19 16:21:35.860: I/dalvikvm(5577): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:21:35.860: I/dalvikvm(5577): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:21:35.860: I/dalvikvm(5577): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:21:35.860: I/dalvikvm(5577): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:21:35.860: I/dalvikvm(5577): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:21:35.860: I/dalvikvm(5577): at dalvik.system.NativeStart.main(Native Method)
05-19 16:21:35.860: D/skia(5577): --- allocation failed for scaled bitmap
05-19 16:21:35.870: D/AndroidRuntime(5577): Shutting down VM
05-19 16:21:35.870: W/dalvikvm(5577): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:21:35.870: E/AndroidRuntime(5577): FATAL EXCEPTION: main
05-19 16:21:35.870: E/AndroidRuntime(5577): Process: com.guesstheyear, PID: 5577
05-19 16:21:35.870: E/AndroidRuntime(5577): java.lang.OutOfMemoryError
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:445)
05-19 16:21:35.870: E/AndroidRuntime(5577): at com.guesstheyear.model.ImageLoader2.setPic(ImageLoader2.java:33)
05-19 16:21:35.870: E/AndroidRuntime(5577): at com.guesstheyear.activities.GameActivity.onWindowFocusChanged(GameActivity.java:155)
05-19 16:21:35.870: E/AndroidRuntime(5577): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2647)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.view.View.dispatchWindowFocusChanged(View.java:7900)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3140)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.os.Looper.loop(Looper.java:136)
05-19 16:21:35.870: E/AndroidRuntime(5577): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:21:35.870: E/AndroidRuntime(5577): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:21:35.870: E/AndroidRuntime(5577): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:21:35.870: E/AndroidRuntime(5577): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:21:35.870: E/AndroidRuntime(5577): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:21:35.870: E/AndroidRuntime(5577): at dalvik.system.NativeStart.main(Native Method)
05-19 16:21:38.310: I/Process(5577): Sending signal. PID: 5577 SIG: 9
05-19 16:21:40.510: V/RenderScript(6169): Application requested CPU execution
05-19 16:21:40.510: V/RenderScript(6169): 0x76ca9340 Launching thread(s), CPUs 4
05-19 16:21:45.360: W/GAV3(6169): Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
05-19 16:21:45.360: I/GAV3(6169): Thread[GAThread,5,main]: No campaign data found.
05-19 16:21:50.360: W/GAV3(6169): Thread[Service Reconnect,5,main]: Service unavailable (code=1), using local store.
05-19 16:23:08.680: D/AndroidRuntime(6169): Shutting down VM
05-19 16:23:08.680: W/dalvikvm(6169): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:08.680: E/AndroidRuntime(6169): FATAL EXCEPTION: main
05-19 16:23:08.680: E/AndroidRuntime(6169): Process: com.guesstheyear, PID: 6169
05-19 16:23:08.680: E/AndroidRuntime(6169): java.lang.NullPointerException
05-19 16:23:08.680: E/AndroidRuntime(6169): at com.guesstheyear.activities.QuickGameActivity$2.onClick(QuickGameActivity.java:310)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.view.View.performClick(View.java:4438)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.view.View$PerformClick.run(View.java:18422)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.os.Handler.handleCallback(Handler.java:733)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:08.680: E/AndroidRuntime(6169): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:08.680: E/AndroidRuntime(6169): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:08.680: E/AndroidRuntime(6169): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:08.680: E/AndroidRuntime(6169): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:08.680: E/AndroidRuntime(6169): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:08.680: E/AndroidRuntime(6169): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:09.780: I/Process(6169): Sending signal. PID: 6169 SIG: 9
05-19 16:23:13.540: D/dalvikvm(6464): GC_FOR_ALLOC freed 27K, 1% free 41293K/41364K, paused 11ms, total 11ms
05-19 16:23:13.600: D/dalvikvm(6464): GC_FOR_ALLOC freed 10K, 1% free 45690K/45748K, paused 11ms, total 11ms
05-19 16:23:13.760: V/RenderScript(6464): Application requested CPU execution
05-19 16:23:13.770: V/RenderScript(6464): 0x79e09658 Launching thread(s), CPUs 4
05-19 16:23:14.450: D/AndroidRuntime(6464): Shutting down VM
05-19 16:23:14.450: W/dalvikvm(6464): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:14.450: E/AndroidRuntime(6464): FATAL EXCEPTION: main
05-19 16:23:14.450: E/AndroidRuntime(6464): Process: com.guesstheyear, PID: 6464
05-19 16:23:14.450: E/AndroidRuntime(6464): java.lang.NullPointerException
05-19 16:23:14.450: E/AndroidRuntime(6464): at com.guesstheyear.activities.QuickGameActivity$2.onClick(QuickGameActivity.java:310)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.view.View.performClick(View.java:4438)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.view.View$PerformClick.run(View.java:18422)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.os.Handler.handleCallback(Handler.java:733)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:14.450: E/AndroidRuntime(6464): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:14.450: E/AndroidRuntime(6464): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:14.450: E/AndroidRuntime(6464): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:14.450: E/AndroidRuntime(6464): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:14.450: E/AndroidRuntime(6464): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:14.450: E/AndroidRuntime(6464): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:17.830: D/AndroidRuntime(6515): Shutting down VM
05-19 16:23:17.830: W/dalvikvm(6515): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:17.830: E/AndroidRuntime(6515): FATAL EXCEPTION: main
05-19 16:23:17.830: E/AndroidRuntime(6515): Process: com.guesstheyear, PID: 6515
05-19 16:23:17.830: E/AndroidRuntime(6515): java.lang.NullPointerException
05-19 16:23:17.830: E/AndroidRuntime(6515): at com.guesstheyear.model.Constants.getType(Constants.java:47)
05-19 16:23:17.830: E/AndroidRuntime(6515): at com.guesstheyear.activities.FinalScoreActivity$3.onClick(FinalScoreActivity.java:103)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.view.View.performClick(View.java:4438)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.view.View$PerformClick.run(View.java:18422)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.os.Handler.handleCallback(Handler.java:733)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:17.830: E/AndroidRuntime(6515): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:17.830: E/AndroidRuntime(6515): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:17.830: E/AndroidRuntime(6515): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:17.830: E/AndroidRuntime(6515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:17.830: E/AndroidRuntime(6515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:17.830: E/AndroidRuntime(6515): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:19.410: I/Adreno-EGL(6532): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-19 16:23:19.440: D/OpenGLRenderer(6532): Enabling debug mode 0
05-19 16:23:19.450: D/AndroidRuntime(6532): Shutting down VM
05-19 16:23:19.450: W/dalvikvm(6532): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:19.450: E/AndroidRuntime(6532): FATAL EXCEPTION: main
05-19 16:23:19.450: E/AndroidRuntime(6532): Process: com.guesstheyear, PID: 6532
05-19 16:23:19.450: E/AndroidRuntime(6532): java.lang.NullPointerException
05-19 16:23:19.450: E/AndroidRuntime(6532): at com.guesstheyear.activities.GameActivity.onWindowFocusChanged(GameActivity.java:155)
05-19 16:23:19.450: E/AndroidRuntime(6532): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2647)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.view.View.dispatchWindowFocusChanged(View.java:7900)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3140)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:19.450: E/AndroidRuntime(6532): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:19.450: E/AndroidRuntime(6532): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:19.450: E/AndroidRuntime(6532): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:19.450: E/AndroidRuntime(6532): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:19.450: E/AndroidRuntime(6532): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:19.450: E/AndroidRuntime(6532): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:21.040: I/Adreno-EGL(6573): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-19 16:23:21.070: D/OpenGLRenderer(6573): Enabling debug mode 0
05-19 16:23:21.070: D/AndroidRuntime(6573): Shutting down VM
05-19 16:23:21.070: W/dalvikvm(6573): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:21.070: E/AndroidRuntime(6573): FATAL EXCEPTION: main
05-19 16:23:21.070: E/AndroidRuntime(6573): Process: com.guesstheyear, PID: 6573
05-19 16:23:21.070: E/AndroidRuntime(6573): java.lang.NullPointerException
05-19 16:23:21.070: E/AndroidRuntime(6573): at com.guesstheyear.activities.GameActivity.onWindowFocusChanged(GameActivity.java:155)
05-19 16:23:21.070: E/AndroidRuntime(6573): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2647)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.view.View.dispatchWindowFocusChanged(View.java:7900)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3140)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:21.070: E/AndroidRuntime(6573): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:21.070: E/AndroidRuntime(6573): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:21.070: E/AndroidRuntime(6573): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:21.070: E/AndroidRuntime(6573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:21.070: E/AndroidRuntime(6573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:21.070: E/AndroidRuntime(6573): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:22.220: D/dalvikvm(6589): Late-enabling CheckJNI
05-19 16:23:22.310: I/Adreno-EGL(6589): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-19 16:23:22.340: D/OpenGLRenderer(6589): Enabling debug mode 0
05-19 16:23:22.350: D/AndroidRuntime(6589): Shutting down VM
05-19 16:23:22.350: W/dalvikvm(6589): threadid=1: thread exiting with uncaught exception (group=0x41ee7ba8)
05-19 16:23:22.350: E/AndroidRuntime(6589): FATAL EXCEPTION: main
05-19 16:23:22.350: E/AndroidRuntime(6589): Process: com.guesstheyear, PID: 6589
05-19 16:23:22.350: E/AndroidRuntime(6589): java.lang.NullPointerException
05-19 16:23:22.350: E/AndroidRuntime(6589): at com.guesstheyear.activities.GameActivity.onWindowFocusChanged(GameActivity.java:155)
05-19 16:23:22.350: E/AndroidRuntime(6589): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2647)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.view.View.dispatchWindowFocusChanged(View.java:7900)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3140)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.os.Looper.loop(Looper.java:136)
05-19 16:23:22.350: E/AndroidRuntime(6589): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 16:23:22.350: E/AndroidRuntime(6589): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:23:22.350: E/AndroidRuntime(6589): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 16:23:22.350: E/AndroidRuntime(6589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 16:23:22.350: E/AndroidRuntime(6589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 16:23:22.350: E/AndroidRuntime(6589): at dalvik.system.NativeStart.main(Native Method)
05-19 16:23:26.080: I/Process(6589): Sending signal. PID: 6589 SIG: 9
05-19 16:23:47.660: D/dalvikvm(6748): GC_FOR_ALLOC freed 46K, 1% free 16922K/17004K, paused 17ms, total 17ms
05-19 16:23:47.670: I/dalvikvm-heap(6748): Grow heap (frag case) to 25.554MB for 9437200-byte allocation
05-19 16:23:47.690: D/dalvikvm(6748): GC_FOR_ALLOC freed 1K, 1% free 26137K/26224K, paused 13ms, total 13ms
05-19 16:23:49.120: D/dalvikvm(6748): GC_FOR_ALLOC freed 360K, 2% free 26522K/26916K, paused 17ms, total 17ms
05-19 16:23:49.130: I/dalvikvm-heap(6748): Grow heap (frag case) to 30.168MB for 4446016-byte allocation
05-19 16:23:49.160: D/dalvikvm(6748): GC_FOR_ALLOC freed 71K, 2% free 30792K/31260K, paused 26ms, total 26ms
05-19 16:23:49.220: D/dalvikvm(6748): GC_FOR_ALLOC freed 173K, 3% free 30688K/31320K, paused 11ms, total 11ms
05-19 16:23:49.220: I/dalvikvm-heap(6748): Grow heap (frag case) to 34.237MB for 4446016-byte allocation
05-19 16:23:49.240: D/dalvikvm(6748): GC_FOR_ALLOC freed 1K, 2% free 35028K/35664K, paused 13ms, total 13ms
05-19 16:23:49.350: I/Adreno-EGL(6748): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-19 16:23:49.380: D/OpenGLRenderer(6748): Enabling debug mode 0
05-19 16:23:49.510: V/RenderScript(6748): Application requested CPU execution
05-19 16:23:49.510: V/RenderScript(6748): 0x76ee8c00 Launching thread(s), CPUs 4
05-19 16:23:54.060: W/GAV3(6748): Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
05-19 16:23:54.060: I/GAV3(6748): Thread[GAThread,5,main]: No campaign data found.
05-19 16:23:59.070: W/GAV3(6748): Thread[Service Reconnect,5,main]: Service unavailable (code=1), using local
如果您需要代码中的任何内容,请向我索取。
提前谢谢。
答案 0 :(得分:0)
试试这个,
public static Bitmap decodeSampledBitmapFromResource(String strPath,int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(strPath, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options,reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(strPath, options);;
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and
// keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
这可能会对你有所帮助