开发者

what is the relation between Canvas and Bitmap?

What is the relation between Canvas and Bitmap?

Bitmap drawingBitmap = Bitmap.createBitmap(bmp1.getWidth(),
bmp1.getHeight(), bmp1.getConfig());
canvas = new Canvas(drawingBitmap);
paint = new Paint();
canvas.drawBitmap(bmp1, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SCREEN));
canvas.drawBitmap(bmp2, 0, 0, paint);
compositeImageView开发者_运维百科.setImageBitmap(drawingBitmap);

I don't understand this code.Why the drawingBitmap is the composition of bmp1 and bmp2?


Basically, the Canvas is backed by a Bitmap, so when you draw anything using the canvas, the canvas will draw into the Bitmap it was created with. So, when you draw those two bitmaps using the canvas, it's going to composite the bitmaps together and the result will be stored in drawingBitmap, as it's backing the canvas.

Anh's analogy is correct-ish, though probably confusing (and over-simplifying, which I'm also doing above) – as I mentioned in a comment, you can think of the Canvas as the pen, the Paint as a configuration of that pen (e.g., replaceable ink or something - whatever you can fit into the idea of a configurable pen), and the Bitmap as the paper you draw onto. The analogy becomes confusing if you focus too much on the accepted meaning of the words.


Let's think canvas as a pen, and drawingBitmap as a paper. You use your pen to draw something on your paper, and you get what you draw. Technically, you can construct Canvas object from Bitmap to draw others bitmaps on it.


Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜