如何获取画布当前的位图?
我想获取与我的画布关联的当前位图,以便我可以对其执行操作。但我不知道该怎么做。
我见过一些创建位图并将画布设置为使用该位图的示例,因此显然您可以稍后访问它,但我使用的是从 SurfaceHolder 返回的画布,因此没有构造函数。
例如,例子经常显示这种事情:
Bitmap bmp = Bitmap.createBitmap(xxx, yyy, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
- 所以此时我可以看到bmp。
就我而言,画布是通过以下方式获取的:
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
那么如何获取 c 的位图?
编辑 @Reuben - 你可能是对的,我确实想知道这一点。简而言之,我的目标是捕获我绘制“东西”的当前画布内容,并复制它,反转,放在下面。就像倒影一样。我发现这个例子是通过位图执行的,所以我假设我需要以某种方式将当前画布捕获到位图然后使用它。如果有更好的方法可以做到这一点,我洗耳恭听!
I want to get the current bitmap associated with my canvas so I can perform operations on it. I can't see how to do this though.
I've seen some examples where you create a bitmap and set the canvas to use this bitmap, so obviously you can then access it later, but I'm using the canvas returned from a SurfaceHolder so there's no constructor.
For instance, examples often show this kind of thing:
Bitmap bmp = Bitmap.createBitmap(xxx, yyy, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
- so at this point I can see bmp.
In my case, the canvas is obtained by:
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
So how can I get the bitmap for c?
Edit
@Reuben - you may be right, I did wonder this. In short, my aim is to capture the current canvas contents where I have drawn "stuff", and make a copy of it, reversed, to put underneath. Like a reflection. The example of this that I found performed it all via bitmaps, so I assumed I needed to somehow capture the current canvas to a bitmap to then use it. If there is a better way I can do this, I'm all ears!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迟到总比不到好:)
然后您可以从 BitmapDrawable 访问位图。
就我而言,我这样做了:
imageView.setImageBitmap(bitmapDrawable.getBitmap());
Better late than never :)
You can then access the bitmap back from the BitmapDrawable.
in my case i did this:
imageView.setImageBitmap(bitmapDrawable.getBitmap());
c.getSurface() 使您可以直接访问 Surface 对象。
c.getSurface() gives you direct access to the Surface object.