How to promote quality of widget screenshot
-
Hi
I want to capture widget to image,but the picture's quality is very low.
I want to promote the clarity of this picture.
How to promote clarity?
This is my code:
QString ui_style;
ui_style=QString("#ImageWidget{image: url(:/img/img.jpg);}");
ui->ImageWidget->setStyleSheet(ui_style);
QImage ui_img = ui->ImageWidget->grab().toImage();
ui_img.save("ui_img.jpg");Thank you very much.
-
The picture will be affected by whatever scaling (up or down) was needed to fit it in ImageWidget. If this is not a whole integer scale then quality may suffer. If this is a large scale up then the image will become worse in various ways, depending on how the engine achieves scaling.
JPEG is a lossy format. Saving the screen grab as JPEG will potentially give a worse result than PNG (lossless).
-
I am not sure why you want to take an image you already have, put it on screen, and then save a screen shot of it, but what you are doing now would achieve that.
QString ui_style; ui_style=QString("#ImageWidget{image: url(:/img/img.jpg);}"); ui->ImageWidget->setStyleSheet(ui_style); QImage ui_img = ui->ImageWidget->grab().toImage(); ui_img.save("ui_img.jpg");
You could start with an image of the correct size and in PNG (lossless) format.
Depending on what type of widgetImageWidget
is, you may be able to display the image directly without the awkward stylesheet. For example QLabel::setPixmap().
You could remove the conversion from QPixmap to QImage in line 5
Save directly from the QPixmap toui_img.png
in line 6