Skip to content

Commit

Permalink
-Updated transparency setting for WMS layers
Browse files Browse the repository at this point in the history
-Should close ticket #1533

git-svn-id: http://svn.osgeo.org/qgis/trunk@10146 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Feb 10, 2009
1 parent 7ada1d9 commit 1f046b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1508,9 +1508,19 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
QgsDebugMsg( QString( "(int)origin y: %1" ).arg( static_cast<int>( myRasterViewPort->topLeftPoint.y() ) ) );

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

// Since GDAL's RasterIO can't handle floating point, we have to round to
// the nearest pixel. Add 0.5 to get rounding instead of truncation
Expand Down
6 changes: 4 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -523,8 +523,10 @@ QImage* QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
{
delete cachedImage;
}
cachedImage = new QImage();
*cachedImage = QImage::fromData( imagesource );

//Create a local image from source then convert it to RGBA, so we can set the transparency later
QImage myLocalImage = QImage::fromData( imagesource );
cachedImage = new QImage( myLocalImage.convertToFormat( QImage::Format_ARGB32 ) );

// Remember settings for useful caching next time.
cachedViewExtent = viewExtent;
Expand Down

0 comments on commit 1f046b8

Please sign in to comment.