Hi,
I need to convert a 8bpp gray DIB image to a QImage or QPixmap.
I had been trying multiple ways but it seems to not work.
This is the code:
Code:
int iWidth = pDib->Width(); int iHeight = pDib->Height(); int iBytes = iWidth*iHeight; uchar* uData = new uchar[iWidth*iHeight]; strncpy((char*)uData,(char*)pDib->GetLinePtr(0),iBytes); image->setNumColors(256); image->setColorTable(m_qPalette); bool bSave = pImage->save("image.jpg","JPG"); //Returns true, but the image is all gray
This other code takes care that the QImage have to be 32 bit aligned:
Code:
int iWidth = pDib->Width(); int iHeight = pDib->Height(); int iBytes = iWidth*iHeight; uchar* uData = new uchar[iWidth*iHeight]; int iColumnsAdd = (iWidth % 4); uchar* uData2 = qImatge->bits(); int iOriginalLineStart; int iDestLineStart; for (int i=0; i<iHeight; i++) { iOriginalLineStart = i*iWidth; iDestLineStart = ((i*iWidth) + (i*iColumnsAdd)); memcpy(uData2+iDestLineStart,uData+iOriginalLineStart,iWidth); } qImatge->setNumColors(256); qImatge->setColorTable(m_qPalette); return(qImatge); bool bSave = pImage->save("image.jpg","JPG"); //Returns true, but the image is all gray
Thanks,
