绘图后,位图不在画布上

时间:2022-06-14 21:19:44

I am drawing a Bitmap with canvas.drawBitmap(bmp, 0, 0, null); to my canvas and the bitmap will just not show. Any ideas?

我正在使用canvas.drawBitmap(bmp,0,0,null)绘制一个Bitmap;到我的画布和位图将不会显示。有任何想法吗?

Thank you!

            Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());
            //Bitmap bmp = BitmapFactory.decodeStream(bis);

            Log.i(TAG, "builded Bitmap");               
            Log.i(TAG, "scaling bitmap...");


            //int scale;
            //Matrix matrix = new Matrix();
            //matrix.setScale(0.1F, 0.1F);
            //if (bmp.getWidth() < bmp.getHeight()){
            //  scale = canvas.getWidth()/bmp.getWidth();
            //}else{
            //  scale = canvas.getHeight()/bmp.getHeight();
            //}
            //matrix.postScale(scale, scale, bmp.getWidth(), bmp.getHeight());
            //matrix.postScale(0.5F, canvas.getWidth()/bmp.getWidth());

            //Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), true);

            //Paint p = new Paint();
            //p.setFilterBitmap(true);


            //try{
            bmp  = Bitmap.createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), true);
            Log.i(TAG, "scaled");
            Log.i(TAG, "showing bitmap...");
            canvas.drawBitmap(bmp, 0, 0, null);
            Log.i(TAG, "showed bitmap");

2 个解决方案

#1


0  

Can you draw a line? Either call invalidate() or postInvalidate().

你能画一条线吗?调用invalidate()或postInvalidate()。

Read Drawing here: http://developer.android.com/reference/android/view/View.html

在这里阅读绘图:http://developer.android.com/reference/android/view/View.html

And copy some examples like: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html

并复制一些示例,如:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html

#2


0  

Just a guess:

只是一个猜测:

Instead of "Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath()); " try "Bitmap bmp = BitmapFactory.decodeStream(..);"

而不是“Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());”try“Bitmap bmp = BitmapFactory.decodeStream(..);”

#1


0  

Can you draw a line? Either call invalidate() or postInvalidate().

你能画一条线吗?调用invalidate()或postInvalidate()。

Read Drawing here: http://developer.android.com/reference/android/view/View.html

在这里阅读绘图:http://developer.android.com/reference/android/view/View.html

And copy some examples like: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html

并复制一些示例,如:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html

#2


0  

Just a guess:

只是一个猜测:

Instead of "Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath()); " try "Bitmap bmp = BitmapFactory.decodeStream(..);"

而不是“Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());”try“Bitmap bmp = BitmapFactory.decodeStream(..);”