How to fit the image to the frame size and maintain the quality of the image without losing any pixel quality in QQuickpainteditems
-
Hi Team,
I have a custom class where i am overriding the paint method to draw an image which is quite large (5000 * 6000) pixels.
i want to make sure the picture fits my framesize keeping the aspectratio and still maintain the quality of the image when scaled down to fit the outer rectangle that contains this custom imageviewer class:this is my paint method:
QRectF bounds = boundingRect();
QImage scaled = m_image.scaledToHeight(m_image.height());
QPointF center = bounds.center() - scaled.rect().center();QPointF topLeft = bounds.topLeft();
// Draw the image
qreal scaleX = static_cast<qreal>(width()) / static_cast<qreal>(m_image.width());
qreal scaleY = static_cast<qreal>(height()) / static_cast<qreal>(m_image.height());
qreal scaleFactor = qMin(scaleX, scaleY);QImage resizedImage = m_image.scaledToWidth(m_image.width() * scaleFactor , Qt::SmoothTransformation);
painter.drawImage(topLeft, resizedImage);
what Am i doing wrong?
or how can i can achieve this? -
Hi Team,
I have a custom class where i am overriding the paint method to draw an image which is quite large (5000 * 6000) pixels.
i want to make sure the picture fits my framesize keeping the aspectratio and still maintain the quality of the image when scaled down to fit the outer rectangle that contains this custom imageviewer class:this is my paint method:
QRectF bounds = boundingRect();
QImage scaled = m_image.scaledToHeight(m_image.height());
QPointF center = bounds.center() - scaled.rect().center();QPointF topLeft = bounds.topLeft();
// Draw the image
qreal scaleX = static_cast<qreal>(width()) / static_cast<qreal>(m_image.width());
qreal scaleY = static_cast<qreal>(height()) / static_cast<qreal>(m_image.height());
qreal scaleFactor = qMin(scaleX, scaleY);QImage resizedImage = m_image.scaledToWidth(m_image.width() * scaleFactor , Qt::SmoothTransformation);
painter.drawImage(topLeft, resizedImage);
what Am i doing wrong?
or how can i can achieve this? -
@kaushikv you will lose resolution by scaling image. If you want to keep good resolution, create the source image with format svg.
-
@kaushikv you will lose resolution by scaling image. If you want to keep good resolution, create the source image with format svg.