使用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();
要怎么才能去掉这个错误提示啊
weixin_慕瓜0466410
凤凰求蛊
开心每一天1111
杨__羊羊
相关分类