I used canvas.drawbitmap(bitmap,matrix,paint)
to draw the bitmap on canvas.
yes, it worked most of the time! But sometimes it did not work. There was nothing on canvas after I called the method canvas.drawbitmap();
So, what`s wrong?
1: I chose a picture from the album and got the Bitmap which named bgBitmap
2: Created a CanvasView
which extends View
. Then Create a empty bitmap on canvas that to paint something on it.
mBitmap = Bitmap.createBitmap(screenWidth, screenHeight,Bitmap.Config.RGB_565);
mCanvas = new Canvas(mBitmap);
mCanvas.drawColor(Color.WHITE);
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(getResources().getColor(R.color.color_white));
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
}
3: draw the picture on the canvas.
mCanvas.drawBitmap(bgBitmap,matrix, bitmapPaint);
this.invalidate();
It worked on most of the time, but sometimes it did not work.