Question

I need to write simple program which can open any BMP file, use RLE compression, save result, open it again and decompress file to normal BMP. Problem is I do not know how to get RGB components of file. There are so many version of BMP standard. I know how to open it in Qt, how to create, and how load in to widget, but I can not find a way to read file information and headers in one bytearray and RGB values in another. Is there in Qt some methods to do that?

Était-ce utile?

La solution

QImage will load the image for you. BMP is one of the supported formats. You shouldn't care about the BMP standard used since Qt handles it internally.

You can access the RGB value of any pixel using the pixel method of QImage.

QImage image;
image.load("myimage.bmp");
QVector<QRgb> imageRGBValues;

for (unsigned i=0; i<image.width(); ++i)
{
   for (unsigned j=0; j<image.height(); ++j)
      imageRGBValues.push_back(image.pixel(i,j));
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top