Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

converting a canvas into bitmap image in android

I am trying to develop an app on canvas,I am drawing a bitmap on the canvas. After drawing, I am trying to convert into bitmap image.

Can anyone give me a suggestion?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Advice depends upon what you are trying to do.

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. Create a bitmap of the correct size using Bitmap.createBitmap()
  2. Create a canvas instance pointing that this bitmap using Canvas(Bitmap) constructor
  3. Draw to the canvas
  4. Use the bitmap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...