开发者

How to obtain the current bitmap of a canvas?

I want to get the current bitmap associated with my canvas so I can perform operations on it. I can't see how to d开发者_JAVA百科o 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!


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());


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜