FILE *BMPFile = fopen(FileName.toAscii().data(), "rb"); // Read Header fileHeader.TypeBMP = read_u16(BMPFile); fileHeader.SizeDataBMP = read_u32(BMPFile); fileHeader.Reserved1BMP = read_u16(BMPFile); fileHeader.Reserved2BMP = read_u16(BMPFile); fileHeader.OffBitsBMP = read_u32(BMPFile); fileHeader.SizeInfoBMP = read_u32(BMPFile); fileHeader.WidthBMP = read_s32(BMPFile); fileHeader.HeightBMP = read_s32(BMPFile); fileHeader.PlanesBMP = read_u16(BMPFile); fileHeader.BitCountBMP = read_u16(BMPFile); fileHeader.CompressionBMP = read_u32(BMPFile); fileHeader.SizeImageBMP = read_u32(BMPFile); fileHeader.XPelsPerMeterBMP = read_s32(BMPFile); fileHeader.YPelsPerMeterBMP = read_s32(BMPFile); fileHeader.ClrUsedBMP = read_u32(BMPFile); fileHeader.ClrImportantBMP = read_u32(BMPFile); // Pixel Array pixelArray = new rgbQuad[fileHeader.HeightBMP * fileHeader.WidthBMP]; // Read Bytes for (int i = 0; i < fileHeader.HeightBMP * fileHeader.WidthBMP; i++) { pixelArray[i].rgbBlue = getc(BMPFile); pixelArray[i].rgbGreen = getc(BMPFile); pixelArray[i].rgbRed = getc(BMPFile); } fclose(BMPFile);
pixArray = bitmapData->getPixelArray(); widthBMP = bitmapData->getBitmapWidth(); heightBMP = bitmapData->getBitmapHeight(); img = new QImage(widthBMP+1, heightBMP+1, QImage::Format_RGB32);QRgb rgb; int x = 0; int y = 0; for(int i = 0; i < widthBMP * heightBMP; i++) { rgb = qRgb(pixArray[i].rgbRed, pixArray[i].rgbGreen, pixArray[i].rgbBlue); if(x >= widthBMP) { x = 0; ++y; } else x++; img->setPixel(x, heightBMP-y, rgb); } QPainter painter(this); painter.drawImage(0,0,*img,0,0,-1,-1,Qt::AutoColor);
fileHeader.WidthBMP = read_s32(BMPFile);
C++ (Qt)img = new QImage(widthBMP+1, heightBMP+1, QImage::Format_RGB32);
img->setPixel(x, heightBMP-y, rgb);
C++ (Qt)QFile file(FileName);file.open(QIODevice::ReadOnly); QDataStream data(&file); ... int skipBites = 0;while ((fileHeader.WidthBMP * fileHeader.BitCountBMP / 8 + skipBites) % 4 != 0) skipBites++; for (int i = 0; i < fileHeader.HeightBMP * fileHeader.WidthBMP; i++) { data >> pixelArray[i].rgbBlue; data >> pixelArray[i].rgbGreen; data >> pixelArray[i].rgbRed; if (skipBites > 0 && ((i + 1) % fileHeader.WidthBMP == 0)) { data.skipRawData(skipBites); }} file.close();
C++ (Qt)widthBMP = bitmapData->getBitmapWidth();heightBMP = bitmapData->getBitmapHeight();img = new QImage(widthBMP, heightBMP, QImage::Format_RGB32); QRgb rgb;int x = 0;int y = 0; for(int i = 0; i < widthBMP * heightBMP; i++){ rgb = qRgb(pixArray[i].rgbRed, pixArray[i].rgbGreen, pixArray[i].rgbBlue); img->setPixel(x, heightBMP-y-1, rgb); if(x >= widthBMP - 1) { x = 0; ++y; } else x++;}