E/BufferQueueProducer 错误

使用MediaProjection API进行屏幕截图的时候,会不断给出:

E/BufferQueueProducer: [ImageReader-1080x1920f1m2-22674-60] dequeueBuffer: BufferQueue has been abandoned

这样一个错误提示,大概一秒钟报十几次...
截图的代码如下:

    ImageReader imageReader = ImageReader.newInstance(screen.getWidth(),
            screen.getHeight(), PixelFormat.RGBA_8888, 2);
            
    VirtualDisplay virtualDisplay = mediaProjection.createVirtualDisplay("screen-mirror",
            screen.getWidth(), screen.getHeight(), screen.getDensity(),
            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, imageReader.getSurface(),
            null, null);
            
    SystemClock.sleep(1000);
    Image image = imageReader.acquireLatestImage();
    int width = image.getWidth();
    int height = image.getHeight();
    final Image.Plane[] planes = image.getPlanes();
    final ByteBuffer buffer = planes[0].getBuffer();
    //每个像素的间距
    int pixelStride = planes[0].getPixelStride();
    //总的间距
    int rowStride = planes[0].getRowStride();
    int rowPadding = rowStride - pixelStride * width;
    Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888);

    bitmap.copyPixelsFromBuffer(buffer);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, screen.getWidth(), screen.getHeight());
    image.close();
    imageReader.close();

要怎么才能去掉这个错误提示啊

HUWWW
浏览 3386回答 4
4回答

weixin_慕瓜0466410

请问楼主解决了吗?

凤凰求蛊

我也 遇到了 这个问题,有人知道怎么解决吗

开心每一天1111

遇到同样的问题,请问解决了吗,咨询下解决方案

杨__羊羊

imageReader可能会被gc,把它变成field就可以了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java