如何获取画布当前的位图?

发布于 2024-10-02 21:42:32 字数 663 浏览 3 评论 0原文

我想获取与我的画布关联的当前位图,以便我可以对其执行操作。但我不知道该怎么做。

我见过一些创建位图并将画布设置为使用该位图的示例,因此显然您可以稍后访问它,但我使用的是从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下凄凉 2024-10-09 21:42:32

迟到总比不到好:)

BitmapDrawable bitDrawable = new BitmapDrawable();
bitmapDrawable.draw(videoView.getHolder().lockCanvas());

然后您可以从 BitmapDrawable 访问位图。

就我而言,我这样做了:

imageView.setImageBitmap(bitmapDrawable.getBitmap());

Better late than never :)

BitmapDrawable bitDrawable = new BitmapDrawable();
bitmapDrawable.draw(videoView.getHolder().lockCanvas());

You can then access the bitmap back from the BitmapDrawable.

in my case i did this:

imageView.setImageBitmap(bitmapDrawable.getBitmap());

一城柳絮吹成雪 2024-10-09 21:42:32

c.getSurface() 使您可以直接访问 Surface 对象。

c.getSurface() gives you direct access to the Surface object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文