QImageRGB32到QImageRGB24,某种图像的不良结果
QImage RGB32 to QImage RGB24, bad result with some kind of image
我尝试将带有RGB32的QImage
转换为带有RGB24的QImage
。我的代码在这种情况下不起作用:
当图像的BMP标头中有额外的1024个字节时,图像的大小为X*Y*3+54+1024个未知字节。
奇怪的是,如果图像分辨率x==分辨率y,例如:512x512或1024x1024,代码就会工作。无论情况如何:当我在标头中有或没有额外的1024字节时
如果BMP的头中没有额外的1024字节,即使分辨率x不同于分辨率y,一切都很好。我的代码:
QImage * img=new QImage("test.jpg");//load img as RGB32 32bit per pixel whatever the format of input
QImage * tmp_img=new QImage(img->width(),img->height(),QImage::Format_RGB888);// image dest 24bit per pixel
uchar * ptr1=img->bits();
uchar * ptr2=tmp_img->bits();
for( int k1=0,k2=0;k1<img->width()*img->height()*4;k1+=4,k2+=3)//increment k1 by 4 because img format is RGB32
//increment k2 by 3 because tmp_img format is RGB888
{
ptr2[k2]=ptr1[k1];
ptr2[k2+1]=ptr1[k1+1];
ptr2[k2+2]=ptr1[k1];
}
删除了旧答案。
为什么不简单地这样做:
QImage img2 = img->convertToFormat(QImage::Format_RGB888);
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 将图像添加到资源文件夹UWP C++
- 彩色图像的卤化物处理平均值
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 重新定位图像时如何前进到下一个内存块
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 为什么 BMP 图像上的 imwrite 会卡住/不返回?
- Gstreamer:每 5 秒使用多文件墨水保存图像/jpeg
- 如何使用CImg打开图像?
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- QImageRGB32到QImageRGB24,某种图像的不良结果