简体   繁体   English

Android 截图错误:RGBA覆盖BLOB格式缓冲区应该有高度==宽度

[英]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更改为0x40x1ImageFormat.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.

相关问题 ImageReader.getPlanes() 返回异常:RGBA 覆盖 BLOB 格式缓冲区应具有高度 == 宽度 - ImageReader.getPlanes() returns Exception: RGBA override BLOB format buffer should have height == width android如何获取图像斑点的宽度和高度? - android How to get width and height of the image blob? 应该指定Android PercentRelativeLayout的宽度和高度 - Android PercentRelativeLayout width and height should be specified android:将`rgba()`中的颜色转换为十六进制格式 - android : convert color in `rgba()` to hex format android studio SVG 文件导入在第 8 行出现错误:不支持的颜色格式“rgba(0,0,0,0)” - android studio SVG File Import Getting ERROR @ line 8: Unsupported color format "rgba(0,0,0,0)" 为什么 rgba() 方法返回的这个 Mat 看起来是 BGR 格式而不是 RGBA 格式? - Why does this Mat returned by rgba() method appear to have BGR format rather than RGBA format? 如何使用本机代码从RGBA缓冲区创建Android位图? - How to create Android bitmap from RGBA buffer in native code? Android GridView,如何使图像项目具有相同的宽度和高度 - Android GridView, how to make image items have the same width and height Android-如何制作包含3张图片的网格(高度33%,宽度100%) - Android - How to have an grid with 3 images (height 33%, width 100%) 旋转后Android视图宽度和高度没有变化 - Android View width and height have not changed after rotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM