[英]Android screenshot error: RGBA override BLOB format buffer should have height == width
I am trying to take screenshots of my Android device (Samsung Galaxy Tab S5e) using a service.我正在尝试使用服务截取我的 Android 设备(Samsung Galaxy Tab S5e)的屏幕截图。 I am using the code from here .
我正在使用这里的代码。
In the code linked, ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
在链接的代码中,
ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
is used.用来。 Note the
PixelFormat.RGBA_8888
.注意
PixelFormat.RGBA_8888
。 Now, this won't allow me to compile my project and I am greeted with the error: Error: Must be one of: ImageFormat.UNKNOWN, ImageFormat.RGB_565... etc
.现在,这将不允许我编译我的项目,并且我收到错误:
Error: Must be one of: ImageFormat.UNKNOWN, ImageFormat.RGB_565... etc
。
So I tried changing PixelFormat.RGBA_8888
to ImageFormat.JPEG
and it compiles.所以我尝试将
PixelFormat.RGBA_8888
更改为ImageFormat.JPEG
并编译。 However, my app now crashes with the message:但是,我的应用程序现在崩溃并显示以下消息:
RGBA override BLOB format buffer should have height == width
RGBA 覆盖 BLOB 格式缓冲区应具有高度 == 宽度
I've tried changing PixelFormat.RGBA_8888
to 0x4
, 0x1
, ImageFormat.RGB_565
and a few others.我尝试将
PixelFormat.RGBA_8888
更改为0x4
、 0x1
、 ImageFormat.RGB_565
和其他一些。 Doing so often results in an exception with the message:这样做通常会导致消息异常:
The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4.
生产者 output 缓冲区格式 0x1 与 ImageReader 配置的缓冲区格式 0x4 不匹配。
This is somehow linked with the format described in onImageAvailable(ImageReader reader)
.这与
onImageAvailable(ImageReader reader)
中描述的格式有某种联系。
I've seen the following SO post , and it seems the correct format is device-specific, but I've tried them all and the error is one of the above.我看过以下 SO 帖子,似乎正确的格式是特定于设备的,但我已经尝试了所有这些,错误是上述之一。
I'm at a total loss (and I'm a Java/Android newb), so could really use some help.我完全不知所措(而且我是 Java/Android 新手),所以真的可以使用一些帮助。
Create image reader as follows,如下创建图像阅读器,
ImageReader imageReader =ImageReader.newInstance(width,
height,
PixelFormat.RGBA_8888,
MAX_IMAGE_COUNT);
Then on the image available listener create bitmap as,然后在图像可用的侦听器上创建 bitmap 为,
try {
image = reader.acquireLatestImage();
if (image != null && mImagesProduced == 0){
Image.Plane[] planes = image.getPlanes();
Buffer imageBuffer = planes[0].getBuffer().rewind();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * width;
// create bitmap
bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height,
Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(imageBuffer);
saveImage(context, bitmap);
}
Hope it works希望它有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.