我不能从变量中绘制位图。当我为它加注星标时,我的应用程序崩溃了。
public class krou extends View {
public static int Width = aktivita.width;
public static int Height = aktivita.height;
final Paint mMalovani;
public static Bitmap mBitmap;
public static Bitmap rc;
public void draw(Canvas canvas) {
Paint p = new Paint();
p.setColor(Color.RED);
int ods = (Height - Width) / 2;
Bitmap imageOne = BitmapFactory.decodeResource(getResources(), R.drawable.ri50_z);
Bitmap ImageTwo = BitmapFactory.decodeResource(getResources(), R.drawable.ri50);
rc = ImageTwo;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(rc, Width, Width, true);
Rect dstRectForRender = new Rect(0, odstup, Width, Width + ods);
canvas.drawBitmap(scaledBitmap, null, dstRectForRender, null);
如果我不使用rc
变量,而我简单地使用imageOne
or ImageTwo
,一切都很好。
谢谢你的建议。
我的日志猫:
09-01 19:29:16.197: E/dalvikvm-heap(1472): Out of memory on a 5760016-byte allocation.
09-01 19:29:16.197: I/dalvikvm(1472): "main" prio=5 tid=1 RUNNABLE
09-01 19:29:16.197: I/dalvikvm(1472): | group="main" sCount=0 dsCount=0 obj=0x40a729a0 self=0x2a00bba8
09-01 19:29:16.197: I/dalvikvm(1472): | sysTid=1472 nice=0 sched=0/0 cgrp=apps handle=1073849308
09-01 19:29:16.207: I/dalvikvm(1472): | state=R schedstat=( 3712781811 1124880434 230 ) utm=328 stm=43 core=0
09-01 19:29:16.207: I/dalvikvm(1472): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-01 19:29:16.207: I/dalvikvm(1472): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
09-01 19:29:16.207: I/dalvikvm(1472): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
09-01 19:29:16.207: I/dalvikvm(1472): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:378)
09-01 19:29:16.207: I/dalvikvm(1472): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:408)
09-01 19:29:16.207: I/dalvikvm(1472): at org.vkedco.mobappdev.draw_touch_drive_00001.krouzky.draw(krouzky.java:71)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.View.draw(View.java:13596)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.View.draw(View.java:13715)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.View.draw(View.java:13596)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.217: I/dalvikvm(1472): at android.view.View.draw(View.java:13594)
09-01 19:29:16.227: I/dalvikvm(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.227: I/dalvikvm(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.View.draw(View.java:13594)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.View.draw(View.java:13715)
09-01 19:29:16.237: I/dalvikvm(1472): at android.widget.FrameLayout.draw(FrameLayout.java:467)
09-01 19:29:16.237: I/dalvikvm(1472): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
09-01 19:29:16.237: I/dalvikvm(1472): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-01 19:29:16.248: I/dalvikvm(1472): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-01 19:29:16.248: I/dalvikvm(1472): at android.os.Handler.handleCallback(Handler.java:725)
09-01 19:29:16.248: I/dalvikvm(1472): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 19:29:16.248: I/dalvikvm(1472): at android.os.Looper.loop(Looper.java:137)
09-01 19:29:16.248: I/dalvikvm(1472): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-01 19:29:16.248: I/dalvikvm(1472): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 19:29:16.248: I/dalvikvm(1472): at java.lang.reflect.Method.invoke(Method.java:511)
09-01 19:29:16.248: I/dalvikvm(1472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-01 19:29:16.248: I/dalvikvm(1472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-01 19:29:16.248: I/dalvikvm(1472): at dalvik.system.NativeStart.main(Native Method)
09-01 19:29:16.267: D/skia(1472): --- allocation failed for scaled bitmap
09-01 19:29:16.267: D/AndroidRuntime(1472): Shutting down VM
09-01 19:29:16.298: W/dalvikvm(1472): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-01 19:29:16.348: E/AndroidRuntime(1472): FATAL EXCEPTION: main
09-01 19:29:16.348: E/AndroidRuntime(1472): java.lang.OutOfMemoryError
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:378)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:408)
09-01 19:29:16.348: E/AndroidRuntime(1472): at org.vkedco.mobappdev.draw_touch_drive_00001.krouzky.draw(krouzky.java:71)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13596)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13715)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13596)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13594)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13594)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.View.draw(View.java:13715)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.widget.FrameLayout.draw(FrameLayout.java:467)
09-01 19:29:16.348: E/AndroidRuntime(1472): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.os.Handler.handleCallback(Handler.java:725)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.os.Looper.loop(Looper.java:137)
09-01 19:29:16.348: E/AndroidRuntime(1472): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-01 19:29:16.348: E/AndroidRuntime(1472): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 19:29:16.348: E/AndroidRuntime(1472): at java.lang.reflect.Method.invoke(Method.java:511)
09-01 19:29:16.348: E/AndroidRuntime(1472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-01 19:29:16.348: E/AndroidRuntime(1472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-01 19:29:16.348: E/AndroidRuntime(1472): at dalvik.system.NativeStart.main(Native Method)
09-01 19:29:24.396: I/Process(1472): Sending signal. PID: 1472 SIG: 9