c++ - QImage RGB32 to QImage RGB24, bad result with some kind of image -
i try convert qimage
rgb32 qimage
rgb24. code doesn't work in case:
when image has additional 1024 bytes in bmp header, size of image x*y*3+54+an unknown 1024 byte.
the strange thing code works if image resolution x == resolution y, example: 512x512 or 1024x1024. whatever situation: when have or don't have additional 1024 byte in header.
if bmp not have additional 1024 byte in header, every thing works fine if resolution x different resolution y. code :
qimage * img=new qimage("test.jpg");//load img rgb32 32bit per pixel whatever 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 4 because img format rgb32 //increment k2 3 because tmp_img format rgb888 { ptr2[k2]=ptr1[k1]; ptr2[k2+1]=ptr1[k1+1]; ptr2[k2+2]=ptr1[k1]; }
removed old answer.
why not this:
qimage img2 = img->converttoformat(qimage::format_rgb888);
Comments
Post a Comment