gpt4 book ai didi

android - 关于Android Drawable的概念

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:51:23 26 4
gpt4 key购买 nike

如何理解Canvas、Drawable、Bitmap、Paint类的概念?他们之间是什么关系?

有人可以给我举个例子吗?

非常感谢。

最佳答案

来自Canvas class文档:

The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).

所以你需要 4 个组件来绘制一些东西。

  1. 位图
  2. Canvas
  3. 可绘制
  4. 画画

假设您想在可绘制文件夹中的背景图片上画一个圆圈。

Canvas canvas;
Bitmap mBG;
Paint mPaint = new mPaint();

mBG = BitmapFactory.decodeResource(res, R.drawable.apple); //Return a bitmap from the image from drawable folder
Canvas.drawBitmap(mBG, 0,0, null); //Draw the bitmap

mPaint.setColor(Color.BLACK); //Set paint to BLACK color
Canvas.drawCircle(100,100,30, mPaint); //Draw circle at coordinate x:100,y:100, radius 30 with the paint defined

关于android - 关于Android Drawable的概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5510000/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com