什么是Canvas和位图之间的关系? [英] what is the relation between Canvas and Bitmap?

查看:158
本文介绍了什么是Canvas和位图之间的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

画布和位图之间的关系是什么?

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

我不明白这个code.Why的drawingBitmap是BMP1和BMP2的成分?

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

推荐答案

基本上,画布位图支持,当您用帆布画什么的话,在画布将绘制成位图它与创建。所以,当你使用画布绘制这两个位图,它要复合的位图一起,结果将存储在 drawingBitmap ,因为它支持画布。

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.

这篇关于什么是Canvas和位图之间的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆