我在水平状态下拍摄了屏幕截图,但是我得到的图像确实是垂直屏幕。图片的上部和下部充满黑色。
如何获得水平屏幕的完整图片?
这是我得到的图像。
部分代码:
public void init(Activity activity) {
mediaProjectionManager = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
it = mediaProjectionManager.createScreenCaptureIntent();
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mImageReader = ImageReader.newInstance(sceenWidth, sceenHeight, 0x1, 2);
DisplayMetrics displayMetrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.densityDpi;
activity.startActivityForResult(it, 666);
}
public Bitmap startCapture() {
android.media.Image image = mImageReader.acquireLatestImage();
if (image == null) {
sleep(100);
return startCapture();
}
int width = image.getWidth();
int height = image.getHeight();
final android.media.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;
mBitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888);
mBitmap.copyPixelsFromBuffer(buffer);
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height);
image.close();
return mBitmap;
}