Bmp vs Bitmap
-
Hi.
I tried to find how create bmp file (header, palette information, data ) on Qt but only can find codes in plane C++. I can't use them (maybe becouse I just started with Qt) becouse of just this line @ (BYTE* pBitmapBits, LONG lWidth, LONG lHeight,WORD wBitsPerPixel, LPCTSTR lpszFileName )@ contains a lot of variables that not accepts by Qt. In documentation I found some thing that calls QBitmap but can't find any examples how to actually create bmp with it. Any help will be appreciated. -
You don't have to resort to windows api functions.
Here's a simplest example:@
QPixmap pixmap(400,300);
QPainter painter(&pixmap);//do some drawing
painter.fillRect(0,0,400,300, Qt::red);
painter.drawRect(10,10,100,100);//save to file
pixmap.save("C:\file.bmp");
@ -
this is useful if you will create bitmap from image . I need to do opposite create bitmap from data file and show it as image. In that case data represents by different colors depending of data value and palette in bmp file. I do that with Net and I sure that it possible to do with Qt too.
-
Sorry, but I'm a little confused. First you said you want to create a bmp and now that you want to read from it to create a Qt image?
If so then it's just
@
QPixmap p("C:\file.bmp");
@
I think you need to be more precise what is bitmap and what is image because QImage, QBitmap, bitmap and .bmp file are 4 totally different things. -
sorry I mean to confuse any one. I just don't know where to start and which tool use for my porosity, I try to move my application from Net to Qt and this is really frustrated when something that you could do before you need to discover again
-
I get that. It's always like that when you change language/library.
So what do you want to do actually (leaving language/library specifics aside)? -
I reserve data from some devise that have to be presented in the way user can analyze it.
-
incoming data shows as bitmap . I don't use 24 bit bitmap to be able quickly change colors just by changing palette . User can see data as a picture .
-
Ok, so we can assume you have just an input array of 8-bit values. Something like unsigned char* or BYTE* or PBYTE or whatever alias your input uses. Either way it's just a pointer do the actual 8bit values.
You can create an image from it using "QImage":http://qt-project.org/doc/qt-5/qimage.html#QImage-4, for example:
@
//get these from whatever your input is
int width = ...
int height = ...
uchar* data = ...//you can use this instance as long as the data pointer is valid
QImage img(data, width, height, QImage::Format_Indexed8);
@
With this you can do any number of stuff, eg. change any palette color using "setColor":http://qt-project.org/doc/qt-5/qimage.html#setColor or the whole palette using "setColorTable":http://qt-project.org/doc/qt-5/qimage.html#setColorTable
You can use it to display in a label eg.
@
ui.someLabel->setPixmap(QPixmap::fromImage(img));
@
or paint it in a paintEvent of some widget:
@
QPainter p(this);
p.drawImage(x, y, img);
@
and so on... -
Thank you very much. See you with next question.