绘图后,位图不在画布上

时间:2011-07-02 22:20:17

标签: java android android-canvas

我正在向我的画布绘制带有canvas.drawBitmap(bmp, 0, 0, null);的位图,并且位图将无法显示。有什么想法吗?

谢谢!

            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 个答案:

答案 0 :(得分:0)

你可以划一条线吗? 调用invalidate()或postInvalidate()。

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

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

答案 1 :(得分:0)

只是一个猜测:

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