I have loaded an ECW file into QGIS (v3.28.2 and also tried 3.30) and a transparency band is recognised as "Band 4: AllOpacity (Alpha)", however the raster is still displaying a black background of the raster extent. The alpha band value of this black background is 255. Is there a way I can make this black background transparent? Using GDAL version 3.6.1, ECW Driver: SDK 5.5.
-
Could you share some small test image?– user30184Commented Apr 26, 2023 at 5:58
-
@user30184 I've updated the question with an image– SajCommented Apr 26, 2023 at 6:21
-
Thanks. I actually meant a real ECW image that could be downloaded but I suppose I have found such image already.– user30184Commented Apr 26, 2023 at 6:53
-
Could you make a test with this image raw.githubusercontent.com/OSGeo/gdal/master/autotest/gdrivers/…? It works as it should for me.– user30184Commented Apr 26, 2023 at 7:06
-
Other ECW files work for me as well. It must be an issue with how the ECW was created. I have solved the issue using the answer below. Thank you– SajCommented Apr 27, 2023 at 2:00
1 Answer
One problem with ECW images is the 'black' pixels will have some variance in their values, which means you cannot simply set 255,255,255 to be transparent. To make the background transparent you can use the QGIS function "Near Black", which will turn values that are approximately 'black' into true 'black', and then you can set that to be transparent.
This will also convert the ECW to a TIF format image, which may increase the size, so use compression if/when you save it.
-
1Thank you, using the 'Near Black' tool solved the issue for me. However I had to add the '-setalpha' command to replace the bad alpha band with one I could use for setting transparency. I used the answer in this thread: gis.stackexchange.com/questions/234590/…– SajCommented Apr 27, 2023 at 2:04