Android: creating a Bitmap with SurfaceView content

后端 未结 3 1984
甜味超标
甜味超标 2020-12-03 08:29

I\'m afraid to already have the unfortunate answer to this question but just in case... I\'m using a SurfaceView to do some image processing with bitmaps (lights and colors

相关标签:
3条回答
  • 2020-12-03 09:13

    There is no simple way to capture frames of SurfaceView, so you can consider using TextureView instead of SurfaceView: the Bitmap can be retrieved using textureView.getBitmap() method.

    0 讨论(0)
  • 2020-12-03 09:25

    Can you draw your SurfaceView onto a Canvas that's backed by a Bitmap?

        // be sure to call the createBitmap that returns a mutable Bitmap
        Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); 
        Canvas c = new Canvas(b);
        yourSurfaceView.draw(c);
    
    0 讨论(0)
  • For API levels >=24, use the PixelCopy API. Here's an example inside an ImageView:

    public void DrawBitmap(){
        Bitmap surfaceBitmap = Bitmap.createBitmap(600, 600, Bitmap.Config.ARGB_8888);
        PixelCopy.OnPixelCopyFinishedListener listener = copyResult -> {
            // success/failure callback
        };
    
        PixelCopy.request(YourSurfaceView, surfaceBitmap,listener,getHandler());
        // visualize the retrieved bitmap on your imageview
        setImageBitmap(plotBitmap);
        }
    }
    
    0 讨论(0)
提交回复
热议问题