Qt下256彩色BMP&JPG图像生成

QTextCodec* cod=QTextCodec::codecForLocale();
       QImage* image=new QImage(300,200,QImage::Format_RGB32);//("images/20110114091415349_0.jpg");
           QPainter painter;

           painter.begin(image);
            painter.setBrush(Qt::white);
            painter.drawRect(image->rect());
           //painter.drawEllipse(10,20, 80,70); // draw an ellipse
           painter.drawText(10,20,cod->toUnicode("南京*******有限公司 从左拍车头"));
           painter.drawText(10,40,cod->toUnicode("时间:2011-01-12 11:24:53.542"));
           painter.drawText(10,60,cod->toUnicode("速度:87Km/h 限速:60Km/h 超速比:26%"));
           painter.end();

           image->save("kkkk.jpg","JPG");

若要生成bmp图片:

                      image->save("1234.bmp","bmp"); //默认为灰度值

生成bmp的8位256彩色图片:


        setWindowTitle(tr("Paint Demo"));
       QImage displayImage = new QImage(500, 500, QImage::Format_RGB32);
       displayImage->fill(qRgb(128, 128, 128));

你可能感兴趣的:(Qt下256彩色BMP&JPG图像生成)