请写出 yuyv图片数据 转换为QImage的程序
时间: 2024-02-19 14:57:35 浏览: 189
将yuv各种格式的图片转换为jpg格式的
4星 · 用户满意度95%
这是一个简单的yuyv图片数据转换为QImage的程序示例:
```c++
#include <QImage>
QImage yuyvToQImage(const unsigned char* yuyv, int width, int height)
{
QImage image(width, height, QImage::Format_RGB32);
int y, u, v;
int r, g, b;
int index = 0;
for (int j = 0; j < height; j++)
{
uchar* line = image.scanLine(j);
for (int i = 0; i < width; i += 2)
{
y = yuyv[index];
u = yuyv[index + 1] - 128;
v = yuyv[index + 3] - 128;
r = y + (1.370705 * v);
g = y - (0.698001 * v) - (0.337633 * u);
b = y + (1.732446 * u);
r = qBound(0, r, 255);
g = qBound(0, g, 255);
b = qBound(0, b, 255);
line[i * 4 + 2] = r;
line[i * 4 + 1] = g;
line[i * 4] = b;
y = yuyv[index + 2];
r = y + (1.370705 * v);
g = y - (0.698001 * v) - (0.337633 * u);
b = y + (1.732446 * u);
r = qBound(0, r, 255);
g = qBound(0, g, 255);
b = qBound(0, b, 255);
line[i * 4 + 6] = r;
line[i * 4 + 5] = g;
line[i * 4 + 4] = b;
index += 4;
}
}
return image;
}
```
在此程序中,我们先用`QImage`类创建一个RGB32格式的图片,然后遍历每个像素点,将每个yuyv值转换为对应的RGB值,最后设置到对应的像素点上。
阅读全文