How can I get the bitmap of the canvas I get in onDraw?

后端 未结 4 1371
庸人自扰
庸人自扰 2020-12-20 10:51

How can I create the bitmap from the canvas of custom view.

4条回答
  •  醉话见心
    2020-12-20 11:40

    There is no way to extract the Bitmap out of a Canvas. The only way you can access it is to pass it yourself when creating the canvas like this new Canvas(myBitmap) and keep the reference.

    EDIT2: see @Alex comment blow - the approach of passing a Bitmap to the Canvas does not seem to work for more recent versions of Android.

    EDIT : If you don't create the Canvas yourself, you could create a screen-sized Bitmap (or whatever size you need) and then pass it to the Canvas in onDraw calls like this: canvas.setBitmap(myBitmap).

提交回复
热议问题