简体   繁体   English

Bitmap 绘图后不在 canvas 上

[英]Bitmap is not on canvas after drawing

I am drawing a Bitmap with canvas.drawBitmap(bmp, 0, 0, null);我正在用canvas.drawBitmap(bmp, 0, 0, null); to my canvas and the bitmap will just not show.我的 canvas 和 bitmap 将不会显示。 Any ideas?有任何想法吗?

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");

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.ZFC35FDC70D5FC69D7526EZ83A83

Just a guess:只是一个猜测:

Instead of "Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath()); " try "Bitmap bmp = BitmapFactory.decodeStream(..);"而不是“Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());”尝试“Bitmap bmp = BitmapFactory.decodeStream(..);”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM