This project has moved and is read-only. For the latest updates, please go here.

Set the transparent color for a rasterlayer

Topics: General Topics, SharpMap Project, SharpMap v0.9 / v1.x
Mar 27, 2009 at 11:07 PM
Hi, I am a beginner on all levels so please assume I know nothing.  I am attemping to use and sharpmap to put a few images on a form.  They are NOAA images for my area.  The first is a .jpg and the rest are .gif files with a transparent color.  If I just add the images, the gif images appear black instead of showing the transparency through to the jpg.  I think it is a problem with the program knowing which color is transparent.  The gif is indexed and for this first image the transparent color is 29.  Using IrfanView to look at the color palette, color 29 is just white (RGB 255,255,255).  So I tried to set the layer2 transparent color to white, but it still doesn't show through to the jpg behind it. 

So my question is how do I get the transparent color from a gif and then set the rasterlayer to use that color?  Thanks,



MapImage1 As New SharpMap.Map(New Size(PictureBox1.Width, PictureBox1.Height))
Dim Layer As SharpMap.Layers.GdalRasterLayer = New SharpMap.Layers.GdalRasterLayer("Topo", "c:\TLX_Topo_Long.jpg")
Dim Layer2 As SharpMap.Layers.GdalRasterLayer = New SharpMap.Layers.GdalRasterLayer("States", "c:\TLX_County_Long.gif")
Layer2.TransparentColor = Color.White
MapImage1.BackColor = Color.White
PictureBox1.Image = MapImage1.GetMap()


Here are the images if you want to test it:
Apr 6, 2009 at 2:10 PM
I am surprised that your image displays at all due to the fact that color palettes aren't currently supported.  To fix your problem, set Layer2.TransparentColor = Color.FromArgb(29, 29, 29)
Apr 22, 2009 at 4:57 PM
Hmm, ok.  That didn't really work too well. 

Well what about using the alpha channel in a png file?  Is that supported in any version of sharpmap?  Any other way to do image transparency/partial transparency?  Thanks