Port MFC BITMAP Code to Qt?
In MFC I used this (ugly) code to display data in bmp Format. Now I have the same Data structure, but want to display it on a QImage. But how do I port this code? (using opensource 4.4 edition)
Code:
void CGraphCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (PixelNumber.x == 0)
return;
//First step: Create BITMAP Header info:
BITMAPINFOHEADER bitmapInfo;
::ZeroMemory(&bitmapInfo,sizeof(BITMAPINFOHEADER));
bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.biWidth = PixelNumber.width();/*enter Width*/
bitmapInfo.biHeight = -PixelNumber.height();/*enter Height*/
bitmapInfo.biPlanes = 1;
bitmapInfo.biBitCount = m_DibColorDepth;
bitmapInfo.biCompression = BI_RGB; //RGB
//bitmapInfo.biSizeImage = bitmapInfo.biWidth*bitmapInfo.biHeight*bitmapInfo.biBitCount/8;
bitmapInfo.biSizeImage = m_DibSize;;
SetDIBitsToDevice(
dc,
0, //dx
0, //dy
PixelNumber.x, // width
PixelNumber.y, // height
0,
0,
0,
PixelNumber.y,
pDIBData,
(LPBITMAPINFO)&bitmapInfo,
DIB_RGB_COLORS);
return;
}
Re: Port MFC BITMAP Code to Qt?
I guess u dont have to care about the bmp format. Qt does it for u.
You can simply read .bmp into QImage, or save as - QImage::save("bmpPic.bmp") ;
From the docs -
Quote:
bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const
Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.
Re: Port MFC BITMAP Code to Qt?
Quote:
Originally Posted by
aamer4yu
I guess u dont have to care about the bmp format. Qt does it for u.
You can simply read .bmp into QImage, or save as - QImage::save("bmpPic.bmp") ;
From the docs -
Probably I did not deliver enough details, since your advice has nothing to do with my problem. I want to plot (not save nor load from disk) data which is placed inside a char * Array (here called pDIBData) to a QImage.
In MFC such an Array is converted in the way shown to an Bitmap (*.bmp format) which is then delivered to a function SetDIBitsToDevice which maps the Bitmap to a Pixmap which is printed on the screen.
So in other words: How do I convert DIB char * Data to a QImage, which I can easily print to the screen?
Matthias
Re: Port MFC BITMAP Code to Qt?
ok,, sorry i didnt get u..
Did u have a look at QImage::fromData ??
May be thats what u are looking for :)