Skip to content
Permalink
Browse files

-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
  • Loading branch information
ersts
ersts committed Feb 10, 2009
1 parent 7ada1d9 commit 1f046b8152c836a491124d371c904c6580a01dd7
Showing with 17 additions and 5 deletions.
  1. +13 −3 src/core/raster/qgsrasterlayer.cpp
  2. +4 −2 src/providers/wms/qgswmsprovider.cpp
@@ -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
@@ -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;

0 comments on commit 1f046b8

Please sign in to comment.