首页 > 编程知识 正文

如何将图像转换为rgb,rgb模式的图像有多少个通道

时间:2023-05-06 20:47:28 阅读:9127 作者:3314

您将要使用ImageReader从相机获取RGB图像。 在运行开发者预览版的Nexus 5上使用Android 5.0“L”的Camera2 API。

已为RGB映像设置了SurfaceView。 它工作正常。 众所周知,Android的所有色调映射和颜色增益设置都被指定为在RGB通道上执行,因此相机硬件会生成RGB数据。

可以使用以下方法创建ImageReader,以从ImageReader获取YUV_420_888图像:

imagereader=imagereader.new instance (w,h,image format.YUV _ 420 _ 888,4 );

然后将YUV图像转换为RGB。 但是,这将引入不期望的量化误差和不必要的处理时间,因为我的APP应用需要RGB图像。

但是,如果尝试以这种方式创建图像读取器,则会出现以下情况:

imagereader=imagereader.new instance (w,h,pixel format.RGB _ 888,4 );

捕获图像失败,但发生了以下执行:

ava.lang.unsupportedoperationexception : theproduceroutputbufferformat0x 22 doesn ' tmatchtheimagereader ' sconfiguredbuffffferer veimagesetup (本机方法) at Android.media.imagereader.acquirenextsurfaceimage ) image at Android.media.imagereader

我在两条战线上感到困惑。 首先,输出格式0x22不在PixelFormat或ImageFormat中。 似乎是未记录的原始模式,但无法使用imagereader.newinstance(w、h、0x22,4、4 )进行捕获。 (获得Java.lang.unsupportedoperationexception 3360 invalid。 我想以原始格式捕获,但不能说服ImageFormat接受它(而且其他原始格式ImageFormat.RAW_SENSOR由于某种原因非常慢)。

然后,SurfaceView很乐意使用RGB_888图像,并将其直接放置在屏幕上。 那么为什么ImageReader不能正确接受RGB图像呢? 我做了什么?

请试试这个,从图像中获取RGB。 那对我有帮助:

private byte [ ] rgbvaluesfrombitmap (位图) { colormatrixcolormatrix=new color matrix ); colorfiltercolorfilter=newcolormatrixcolorfilter; bitmapargbbitmap=bitmap.create bitmap (bitmap.getwidth (,bitmap.getHeight ),Bitmap.Config.ARGB_8888 ); canvas canvas=new canvas (argb比特); 绘制点=new paint (; pint.setcolor滤波器(color filter ); canvas.drawbitmap(bitmap,0,0,paint ); int width=bitmap.getWidth (; int height=bitmap.getHeight (; int componentsPerPixel=3; int totalPixels=width * height; int total bytes=total pixels * componentsperpixel; byte [ ] RGB values=new byte [ total bytes ]; @ colorintint [ ] argb pixels=new int [ total pixels ]; argb bitmap.get pixels (argb pixels,0,width,0,0,width,height ); for(intI=0; i totalPixels; I } { @ colorintintargbpixel=argb pixels [ I ]; intred=color.red(ARGBpixel ); intgreen=color.green(argbpixel ); intblue=color.blue(ARGBpixel; RGB values [ I * componentsperpixel0]=(byte ) red; RGB values [ I * componentsperpixel1]=(byte ) green; RGB values [ I *组件sperpixel2]=(byte ) blue; }返回RGB values; }

谢谢你。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。