-1

Im Looking to lower the Resolution of Qpixmap cropped that is then saved a png

   QPixmap original(imgPath); // read in the image that was selected from tree
   QPixmap cropped = original.copy(cropRectInt); // make copy of image that is cropped to the size of the rect

//***Convert cropped to lower res here***//

   QFile file("5.png");
   cropped.save(&file, "PNG"); // save for testing

   QByteArray byteArray;
   QBuffer buffer(&byteArray);
   cropped.save(&buffer, "PNG"); 
   QString imgBase64 = QString::fromLatin1(byteArray.toBase64().data()); 
John
  • 71
  • 1
  • 8
  • 1
    What question are you asking? Are you receiving an error? If so, please add the error to the question. – DAC84 Jul 24 '15 at 08:21
  • 1
    could you elaborate about the problem you are facing ? – Stephane Rolland Jul 24 '15 at 08:22
  • I have been searching for ways to lower the resolution of a Qpixmap without any luck, the main aim is to just reduce the image size – John Jul 24 '15 at 08:24
  • The [QPixmap::scaled](http://doc.qt.io/qt-5/qpixmap.html#scaled-2) function allows you to change the size of the image. – TheDarkKnight Jul 24 '15 at 08:26
  • I didn't think of using that to reduce the amount of data, was thinking of it in a to complicated way. will use something like 'cropped.scaledToHeight(100,Qt::FastTransformation)' – John Jul 24 '15 at 08:43

1 Answers1

1

Try to use quality parameter in call QPixmap::save(QIODevice* device, const char* format, int quality)

You can refer this QT documentation

Amol Saindane
  • 1,568
  • 10
  • 19
timocov
  • 1,088
  • 6
  • 16
  • This was more what I was looking for thanks have changed the save to `cropped.save(&file, "PNG", 50);` – John Jul 24 '15 at 09:01
  • after testing the best method was to use both the 'cropped.scaledToHeight' and the 'cropped.save( , , int quality)' – John Jul 24 '15 at 11:06