前段时间整个一个yuv文件,格式为352x240,YUV420格式的,即YYYYUUVV,准备使用Qt进行重绘显示。不知道为什么转换为RGB显示出来乱乱的,
最近做只显示出Y通道的灰度图像,刚做成功。
灰度图像即RGB三颜色是一样的,需要建立一个8位的256级的灰度索引表,用0~255表示颜色的深度。
然后构建一个8位的QImage并设置它的颜色索引表,让它去颜色表中查颜色。
Qt中的QImage提供了对每一个像素的操作。
关键是setPixel这个函数。
void QImage::setPixel(const QPoint & position, uint index_or_rgb)
Sets the pixel index or color at the given position to index_or_rgb.
If the image's format is either monochrome or 8-bit, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value.
If position is not a valid coordinate pair in the image, or if index_or_rgb >= colorCount() in the case of monochrome and 8-bit images, the result is undefined.
Warning: This function is expensive due to the call of the internal d