|
21 | 21 | #include "qgsexpression.h"
|
22 | 22 | #include "qgsgeometry.h"
|
23 | 23 | #include "qgsgeometrycollection.h"
|
| 24 | +#include "qgsimagecache.h" |
24 | 25 | #include "qgsrendercontext.h"
|
25 | 26 | #include "qgsproject.h"
|
26 | 27 | #include "qgssvgcache.h"
|
@@ -3787,43 +3788,17 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
|
3787 | 3788 |
|
3788 | 3789 | void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context )
|
3789 | 3790 | {
|
3790 |
| - QImage image( imageFilePath ); |
3791 |
| - if ( image.isNull() ) |
3792 |
| - { |
3793 |
| - return; |
3794 |
| - } |
3795 |
| - if ( !image.hasAlphaChannel() ) |
3796 |
| - { |
3797 |
| - image = image.convertToFormat( QImage::Format_ARGB32 ); |
3798 |
| - } |
3799 |
| - |
3800 |
| - double pixelWidth; |
| 3791 | + QSize size; |
3801 | 3792 | if ( width > 0 )
|
3802 | 3793 | {
|
3803 |
| - pixelWidth = context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ); |
3804 |
| - } |
3805 |
| - else |
3806 |
| - { |
3807 |
| - pixelWidth = image.width(); |
3808 |
| - } |
3809 |
| - |
3810 |
| - //reduce alpha of image |
3811 |
| - if ( alpha < 1.0 ) |
3812 |
| - { |
3813 |
| - QPainter p; |
3814 |
| - p.begin( &image ); |
3815 |
| - p.setCompositionMode( QPainter::CompositionMode_DestinationIn ); |
3816 |
| - QColor alphaColor( 0, 0, 0 ); |
3817 |
| - alphaColor.setAlphaF( alpha ); |
3818 |
| - p.fillRect( image.rect(), alphaColor ); |
3819 |
| - p.end(); |
| 3794 | + size.setWidth( context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ) ); |
| 3795 | + size.setHeight( 0 ); |
3820 | 3796 | }
|
3821 | 3797 |
|
3822 |
| - //resize image if required |
3823 |
| - if ( !qgsDoubleNear( pixelWidth, image.width() ) ) |
3824 |
| - { |
3825 |
| - image = image.scaledToWidth( pixelWidth, Qt::SmoothTransformation ); |
3826 |
| - } |
| 3798 | + bool cached; |
| 3799 | + QImage img = QgsApplication::imageCache()->pathAsImage( imageFilePath, size, true, alpha, cached ); |
| 3800 | + if ( img.isNull() ) |
| 3801 | + return; |
3827 | 3802 |
|
3828 |
| - brush.setTextureImage( image ); |
| 3803 | + brush.setTextureImage( img ); |
3829 | 3804 | }
|
0 commit comments