How to correct the Image?



  • Hi i am trying to convert an image in to BMP and then i want to print it, but when i am converting the image to BMP using QImage the image seems as follows

    Please help me to convert the Image to a good quality

    Thanks in advance





  • Could you provide an example image and how it gets out using your method?


  • Qt Champions 2017

    @Rohith
    The forum's image upload is broken, please use an external site (e.g. postimage.org).



  • @kshegunov

    Here is the Link of Image Please Go through It

    https://s12.postimg.org/npwtmfvml/finalimage.jpg


  • Qt Champions 2017

    @Rohith
    It looks strange. How do you make the conversion? And what did you mean by "print', do you want to send the image to a printer, or only to show it on the screen?



  • @kshegunov

    I want to send the image to the printer for printing

    here is code

    QImage img("1.jpg");
                    QImage img1 = img.scaled(QSize(384,500), Qt::IgnoreAspectRatio);
            QBitmap *prnbmp1 = new QBitmap(QBitmap::fromImage((const QImage)img1,Qt::MonoOnly));
               prnbmp1->save("finalimage.bmp","BMP",-1);
           
            QImage img2("finalimage.bmp" );
            img2.save("finalimage.bmp");
            QFile file1("finalimage.bmp");
            qDebug()<<"size of img in bytes"<<file1.size();
    
    

    after converting to Bmp i am sending to printer by converting the BMP to HEX

    here is the Link for Original Image

    https://s10.postimg.org/lj1v7ddy1/image.jpg

    Thanks in advance



  • form http://doc.qt.io/qt-5/qimage.html

    Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

    QImage img("1.jpg");
    QImage img1 = img.scaled(QSize(384,500), Qt::IgnoreAspectRatio);
    img1.convertToFormat(QImage::Format_Mono); //Converts to black and white but original image is already B/W so I'm not sure it's necessary
    img1.save("finalimage.bmp","BMP");
    

  • Qt Champions 2017

    You don't need all this. Just write the image to the file with the appropriate format. E.g:

    QImage img = QImage("1.jpg").scaled(QSize(384,500), Qt::IgnoreAspectRatio);
    if (!img.save("finalimage.bmp", "BMP"))
        ; //< Couldn't save the image, handle the error
    

    Look here for the supported formats.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.