This project is read-only.

MapImageLayer opacity

Nov 15, 2010 at 10:12 PM

How can I set MapImageLayer opacity? I've made a Bitmap image from a Graphics object, which I used to draw large number polygons more easily. I've then scaled image and set the extents and it fits perfectly on a map. I just need to set the opacity now, anywhere in the process of making this layer (Graphics->Bitmap->ImageData->MapImageLayer) where that's possible.

Thanks,

Dragan

Nov 15, 2010 at 10:38 PM
Not really supported yet technically, but the InRamImageData class supports a byte array. If you create your image using that, you could fiddle with the ARGB colors of the bytes. It supports a getColor, setColor method style to make it easier. When you are done, you can call call "WriteBytes, which may or may not have been renamed to BytesToBitmap" depending on which version you are looking at. Since the bitmap is just a .Net bitmap, you can also use a number of System.Drawing tricks using the graphics object for color replacement if that is more accurate with what you need. For instance, if you need to switch white to transparent, that is different from setting the A value to 50 in all pixels, which creates translucence. Here is a quick paste from some random web page that uses the principal. don't use the ARGB values of this instance, since they don't have the A term, but you get the picture.

Graphics g = Graphics.FromImage(myBitmap);
ImageAttributes att = new ImageAttributes();
ColorMap map = new ColorMap();
map.OldColor = Color.FromArgb(66,67,65);
map.NewColor = Color.FromArgb(0x47,0x88,0xc8);
att.SetRemapTable(new ColorMap[] { map });

g.DrawImage(icon,
new Rectangle(x,y,icon.Width,icon.Height),
0,0,icon.Width,icon.Height,GraphicsUnit.Pixel,att);
If you update the bitmap, be sure you invalidate the map frame as well.

Ted

Nov 16, 2010 at 8:03 PM

Thank you so much, Ted! I've just implemented this code in my application. It's exactly what I looked for.

Regards,

Dragan

Dec 21, 2014 at 5:30 PM
Dragan, I am stuck with setting the opacity for imagelayer, can you show me how you solve this problem.

Thanks and regards, Vojko