Skip to content

Commit 1ffa682

Browse files
author
ersts
committed
-merged revision 10146 into branch
-Fixes ticket #1533 git-svn-id: http://svn.osgeo.org/qgis/branches/Version-1_0@10171 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 495c1ce commit 1ffa682

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
@@ -514,8 +514,10 @@ QImage* QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
514514
{
515515
delete cachedImage;
516516
}
517-
cachedImage = new QImage();
518-
*cachedImage = QImage::fromData( imagesource );
517+
518+
//Create a local image from source then convert it to RGBA, so we can set the transparency later
519+
QImage myLocalImage = QImage::fromData( imagesource );
520+
cachedImage = new QImage( myLocalImage.convertToFormat( QImage::Format_ARGB32 ) );
519521

520522
// Remember settings for useful caching next time.
521523
cachedViewExtent = viewExtent;

0 commit comments

Comments
 (0)