Draw smoothly scaled image using QPainter and OpenGLWidget?
-
Hi,
Can you share the code you are using ?
What is the size of the original image ?
What is the target size ? -
Hi,
Can you share the code you are using ?
What is the size of the original image ?
What is the target size ?@SGaist Here's the paintEvent method:
QPainter painter; painter.begin(this); painter.setRenderHint(QPainter::Antialiasing); if (image) { QRect wndRect = this->rect(); painter.drawImage(wndRect, *image, image->rect()); } painter.end();
Original Image size: 1920 x 1080
Widget size: 960 x 540 (50% of original size) -
Did you check QImage::scaled ?
-
Did you check QImage::scaled ?
-
Then you have to make a texture of your image and draw it directly with OpenGL.
-
@SGaist Yes but its too slow and SmoothTransformation setting creates a blurry looking image - when there is text.
Was hoping for OpenGL to take care of scaling etc.
-
@SGaist Just got it working via OpenGL using an example I found online. The problem now is that when I try to update the image by calling setData on texture, then I get following messages in debugger, however, the display is updated without any issues.
QOpenGLTexture::setFormat(): Cannot change format once storage has been allocated
Cannot resize a texture that already has storage allocated.
To do so, destroy() the texture and then create() and setSize()
Cannot set mip levels on a texture that already has storage allocated.
To do so, destroy() the texture and then create() and setMipLevels()I'm updating Texture using code:
texture->setData(image, QOpenGLTexture::MipMapGeneration::DontGenerateMipMaps);
An image with same RGB32 format and same width/height was used to create the texture, so whats the reason for warnings above?