[Interest] QPixmap or QImage::scaled() crash on iOS with smoothTransformation

Allan Sandfeld Jensen kde at carewolf.com
Mon Jul 20 10:57:18 CEST 2015


On Monday 20 July 2015, maitai wrote:
> Hello again,
> 
> FYI there is no such thing as Qt::SmoothScale in QPainter::drawImage or
> QPainter::drawPixmap so I ended up with something like:
> 

Yes, that I why I wrote something like. I hadn't looked up the exact 
arguments.


>      QPixmap pixscaled(QSize(scaleX, scaleY));
>      if(scaleX > pix.width() || scaleY > pix.height()) {
>          pixscaled.fill(Qt::transparent);
>          QPainter painter(&pixscaled);
>          painter.setBackgroundMode(Qt::TransparentMode);
>          painter.setRenderHints(QPainter::Antialiasing, true);
>          painter.setRenderHints(QPainter::SmoothPixmapTransform, true);
>          painter.drawPixmap(QRect(QPoint(0, 0), QSize(scaleX, scaleY)),
> pix);
>          painter.end();
>      } else {
>          pixscaled = pix.scaled(scaleX, scaleY, Qt::IgnoreAspectRatio,
> Qt::SmoothTransformation);
>      }
> 
> and no crash anymore...
> 
Thanks for writing it here. I would use a QImage, but it shouldn't matter. You 
can also use pixscaled.rect() as the destination rect instead of making a 
temporary QRect.

Bonus: This is probably faster, since the scaling in the raster painter has 
NEON optimizations, while the qimage scaler does not.

`Allan



More information about the Interest mailing list