且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在android中将画布转换为位图图像

更新时间:2023-01-23 10:07:07

建议取决于您要尝试做什么.

Advice depends upon what you are trying to do.

如果您担心您的控件需要很长时间来绘制,并且您想绘制到位图以便您可以对位图进行 blit 而不是通过画布重新绘制,那么您不要em> 希望对平台进行双重猜测 - 控件自动将其绘图缓存到临时位图,甚至可以使用 getDrawingCache()

If you are concerned that your controls take a long time to draw, and you want to draw to a bitmap so you can blit the bitmap rather than re-drawing via a canvas, then you don't want to be double-guessing the platform - controls automatically cache their drawing to temporary bitmaps, and these can even be fetched from the control using getDrawingCache()

如果你想使用画布绘制位图,通常的方法是:

If you want to draw using a canvas to a bitmap, the usual recipe is:

  1. 使用 Bitmap.createBitmap()
  2. 使用Canvas(Bitmap) 构造函数
  3. 在画布上绘制
  4. 使用位图