有谁知道它是什么? BufferQueue 已被废弃
我正在使用 Mediaprojectoin 类截屏。我的应用程序运行良好,但在 Logcat 中我有很多行说“BufferQueue 已被放弃”。我不知道它是什么以及我应该做什么。
事实上,我在 android 5 中没有这个问题。仅适用于 android 6+。
这是我的代码:
Display display = wm.getDefaultDisplay();
// final DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
Point size = new Point();
display.getRealSize(size);
final int mWidth = size.x;
final int mHeight = size.y;
int mDensity = metrics.densityDpi;
ImageReader mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
mProjection.createVirtualDisplay("screen-mirror", mWidth, mHeight, mDensity, flags, mImageReader.getSurface(), null, handler);
mImageReader.setOnImageAvailableListener(new mImageListener(handler,metrics,mImageReader),handler);
这是 ImageListener :
class mImageListener implements ImageReader.OnImageAvailableListener{
private Handler handler ;
private DisplayMetrics metrics ;
ImageReader imageReader ;
public mImageListener(Handler handler ,DisplayMetrics metrics , ImageReader imageReader ){
this.handler = handler ;
this.metrics = metrics ;
this.imageReader = imageReader ;
}
@Override
public void onImageAvailable(ImageReader reader) {
reader.setOnImageAvailableListener(null, handler);
Image image = reader.acquireLatestImage();
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 * metrics.widthPixels;
// create bitmap
Bitmap bmp = Bitmap.createBitmap(metrics.widthPixels + (int) ((float) rowPadding / (float) pixelStride), metrics.heightPixels, Bitmap.Config.ARGB_8888);
bmp.copyPixelsFromBuffer(buffer);
image.close();
reader.close();
Bitmap realSizeBitmap = Bitmap.createBitmap(bmp, 0, 0, metrics.widthPixels, bmp.getHeight());
bmp.recycle();
FileOutputStream fos = null;
Bitmap bitmap = realSizeBitmap;
try {
File img1 = new File("/sdcard/DCIM"+"/ins.jpg" ) ;
fos = new FileOutputStream(img1) ;
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) ;
Toast.makeText(getApplicationContext() ,"Screen was taken" ,Toast.LENGTH_LONG ).show();
fos.flush();
fos.close();
imageReader = null ;
}
catch (Exception e){
Toast.makeText(getApplicationContext() , "exception happend + " + e.toString(),Toast.LENGTH_LONG).show() ;
}
}
}
你能帮助我吗 ...