2011-07-02 123 views
0

我在画布上绘制了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"); 

回答

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

+0

如果在绘制位图后绘制一条线,它会起作用!我无法在视图上调用invalidate,因为我没有视图,它的实时背景 – nomoral

0

只是一个猜测:

而不是“BMP位图= BitmapFactory.decodeFile(myfile.getPath()) ; “尝试”位图bmp = BitmapFactory.decodeStream(..);“

+0

'BitmapFactory.decodeFile'是一个解决方法,因为这个bug:http://code.google.com/p/android/issues/detail?编号= 6066 – nomoral

+0

我没有意识到这一点!谢谢! – Chandan