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.
thank you in advance.
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.
thank you in advance.
Other example:
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:
Bitmap.createBitmap()
Canvas(Bitmap)
constructorFollowing are the steps to convert from canvas to bitmap and storing it to gallery or specific folder.
Note: Make sure you have given permission of WRITE_EXTERNAL_STORAGE
activity_main.xml
MainActivity.java
Create reference of parent layout
To store it into gallery
To convert into bitmap
So you create a new
Bitmap
, for example:Bitmap myBitmap = new Bitmap( (int)Width, (int)Height, Config.RGB_565 )
with
width
andheight
being the same as your canvas.Next, use
canvas.setBitmap(myBitmap)
, but notdrawBitmap()
.After you call
setBitmap
, all what you draw on canvas is in fact, drawing on yourmyBitmap
going by the example code I have illustrated.Edit:
You can not create a bitmap directly such as:
You must use instead: