Skip to content

Commit 1f046b8

Browse files
author
ersts
committed
-Updated transparency setting for WMS layers
-Should close ticket #1533 git-svn-id: http://svn.osgeo.org/qgis/trunk@10146 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7ada1d9 commit 1f046b8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/core/raster/qgsrasterlayer.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -1508,9 +1508,19 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
15081508
QgsDebugMsg( QString( "(int)origin y: %1" ).arg( static_cast<int>( myRasterViewPort->topLeftPoint.y() ) ) );
15091509

15101510
//Set the transparency for the whole layer
1511-
QImage myAlphaChannel( image->width(), image->height(), QImage::Format_Indexed8 );
1512-
myAlphaChannel.fill(( uint ) mTransparencyLevel );
1513-
image->setAlphaChannel( myAlphaChannel );
1511+
//QImage::setAlphaChannel does not work quite as expected so set each pixel individually
1512+
//Currently this is only done for WMS images, which should be small enough not to impact performance
1513+
int myWidth = image->width();
1514+
int myHeight = image->height();
1515+
QRgb myRgb;
1516+
for( int myHeightRunner = 0; myHeightRunner < myHeight; myHeightRunner++ )
1517+
{
1518+
for( int myWidthRunner = 0; myWidthRunner < myWidth; myWidthRunner++ )
1519+
{
1520+
myRgb = image->pixel( myWidthRunner, myHeightRunner );
1521+
image->setPixel( myWidthRunner, myHeightRunner, qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), mTransparencyLevel ) );
1522+
}
1523+
}
15141524

15151525
// Since GDAL's RasterIO can't handle floating point, we have to round to
15161526
// the nearest pixel. Add 0.5 to get rounding instead of truncation

src/providers/wms/qgswmsprovider.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ QImage* QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
523523
{
524524
delete cachedImage;
525525
}
526-
cachedImage = new QImage();
527-
*cachedImage = QImage::fromData( imagesource );
526+
527+
//Create a local image from source then convert it to RGBA, so we can set the transparency later
528+
QImage myLocalImage = QImage::fromData( imagesource );
529+
cachedImage = new QImage( myLocalImage.convertToFormat( QImage::Format_ARGB32 ) );
528530

529531
// Remember settings for useful caching next time.
530532
cachedViewExtent = viewExtent;

0 commit comments

Comments
 (0)