Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android屏幕截图错误:RGBA覆盖BLOB格式缓冲区应具有高度==宽度_Android_Image_Image Formats_Pixelformat_Image Reader - Fatal编程技术网

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

Android屏幕截图错误:RGBA覆盖BLOB格式缓冲区应具有高度==宽度,android,image,image-formats,pixelformat,image-reader,Android,Image,Image Formats,Pixelformat,Image Reader,我正在尝试使用一项服务拍摄我的Android设备(三星Galaxy Tab S5e)的屏幕截图。 我正在使用来自的代码 在链接的代码中,ImageReader.newInstance(mWidth,mHeight,PixelFormat.RGBA_8888,2)被使用。请注意PixelFormat.RGBA_8888。现在,这将不允许我编译我的项目,我遇到了一个错误:error:必须是以下之一:ImageFormat.UNKNOWN,ImageFormat.RGB_565。。。etc 因此,我尝

我正在尝试使用一项服务拍摄我的Android设备(三星Galaxy Tab S5e)的屏幕截图。 我正在使用来自的代码

在链接的代码中,
ImageReader.newInstance(mWidth,mHeight,PixelFormat.RGBA_8888,2)被使用。请注意
PixelFormat.RGBA_8888
。现在,这将不允许我编译我的项目,我遇到了一个错误:
error:必须是以下之一:ImageFormat.UNKNOWN,ImageFormat.RGB_565。。。etc

因此,我尝试将
PixelFormat.RGBA_8888
更改为
ImageFormat.JPEG
,并进行编译。但是,我的应用程序现在因以下消息而崩溃:

RGBA覆盖BLOB格式缓冲区的高度应为==宽度

我已尝试将
PixelFormat.RGBA_8888
更改为
0x4
0x1
ImageFormat.RGB_565
和其他一些。这样做通常会导致以下消息出现异常:

生产者输出缓冲区格式0x1与ImageReader配置的缓冲区格式0x4不匹配

这与
onImageAvailable(ImageReader)
中描述的格式有某种联系

我已经看到了,而且似乎正确的格式是特定于设备的,但是我已经尝试了所有的格式,错误是上面的一个


我完全不知所措(我是Java/Android新手),所以我真的需要一些帮助。

创建图像阅读器,如下所示

 ImageReader imageReader =ImageReader.newInstance(width,
            height,
            PixelFormat.RGBA_8888,
            MAX_IMAGE_COUNT);
然后在可用的图像上创建位图,如下所示:

          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);
                }

希望它能工作

创建如下图像阅读器

 ImageReader imageReader =ImageReader.newInstance(width,
            height,
            PixelFormat.RGBA_8888,
            MAX_IMAGE_COUNT);
然后在可用的图像上创建位图,如下所示:

          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);
                }

希望它能起作用

你找到答案了吗?我也有同样的问题。@TeekamSuthar最后我执行了一个
像素复制请求
。请参阅此处的文档和示例:请注意,我没有将其构建到服务中,尽管这应该是可能的。感谢您的快速响应。我要试试这个!面对同样的问题。运气好吗?@UsmanRana检查我的评论你找到答案了吗?我也有同样的问题。@TeekamSuthar最后我执行了一个
像素复制请求
。请参阅此处的文档和示例:请注意,我没有将其构建到服务中,尽管这应该是可能的。感谢您的快速响应。我要试试这个!面对同样的问题。运气好吗?@UsmanRana查看我的评论