我怎样才能得到我得到的OnDraw画布的位图? [英] How can I get the bitmap of the canvas I get in onDraw?
问题描述
我如何可以创建自定义视图画布的位图。
How can I create the bitmap from the canvas of custom view.
推荐答案
有没有办法提取位图
出帆布<的/ code>。您可以访问它的唯一方法是创建这样的画布,当自己把它传递
新的Canvas(MYBITMAP)
并保持基准。
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:看@Alex评论的打击 - 传递的方式一位图
到画布
似乎并不对于Android的较新版本。
see @Alex comment blow - the approach of passing a Bitmap
to the Canvas
does not seem to work for more recent versions of Android.
编辑:如果你没有创建画布
你自己,你可以创建一个屏幕大小的位图
(或者你需要的任何大小),然后将其传递给画布
在的OnDraw
要求是这样的: canvas.setBitmap(MYBITMAP)
。
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)
.
这篇关于我怎样才能得到我得到的OnDraw画布的位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!