Images with transparent background as marker, transparency is lost

Jul 26, 2010 at 7:01 PM

Hi all,

First of all great job creating this library and of course making it available for us. I already implemented the map in a Windows Mobile application, but something won't work. I have a map with incidents to which an ambulance, policecar of firetruck goes. I want to display images at the specified coordinates. Placing the images on the specified location works fine with a layer, but somehow the png-images which have transparent backgrounds lose their transparency. The images are loaded in the resources and are called with my.resources.filename. The following is the complete class which I found somewhere else on this forum:

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports GMap.NET
Imports GMap.NET.CacheProviders
Imports GMap.NET.WindowsForms
Imports GMap.NET.WindowsForms.Markers

Public Class GMapMarkerImage : Inherits GMapMarker
    Dim _image As System.Drawing.Image
    Dim _point As PointLatLng

    Sub New(ByVal iPoint As PointLatLng, ByVal discipline As String)
        _point = iPoint
        Select Case discipline
            Case "politie"
                _image = My.Resources.politie_32
            Case "ambulance"
                _image = My.Resources.ambulance_32
            Case "brandweer"
                _image = My.Resources.brandweer_32
            Case "lifeliner"
                _image = My.Resources.lifeliner_32
            Case "knrm"
                _image = My.Resources.knrm_32
            Case "onbekend"
                _image = My.Resources.onbekend_32
        End Select
    End Sub

    Public Overrides Sub OnRender(ByVal g As System.Drawing.Graphics)
        Dim p As New System.Drawing.Point(_point.Lat, _point.Lng)
        g.DrawImage(_image, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2))
    End Sub
End Class

I add the image to the layer by using the following line:

p2000Layer.Markers.Add(New GMapMarkerImage(New PointLatLng(latitude ,longitude), "ambulance"))

Can someone tell me why the transparency is lost?

Jul 27, 2010 at 4:39 PM

I see no prob here...

think your source is correct.


i usually use g.DrawImageUnscaled to draw the image.


please recheck your ressource-files. i think there is the problem.


greetz manuel

Jul 27, 2010 at 9:36 PM
mobile version has specific marker for transparent objects: GMapMarkerTransparent, because by default there is no transparency support on the device
Jul 28, 2010 at 10:39 AM
Edited Jul 28, 2010 at 5:23 PM

Great, I will check it later this day!

/edit: radioman: do you have a suggestion or a guide how I should implement a custom marker with the GMapMarkerTransparent? Thanks in advance.

Jul 28, 2010 at 5:36 PM
check how is made GMapMarkerTransparentGoogleGreen
Aug 2, 2010 at 1:18 PM
Edited Aug 2, 2010 at 1:18 PM

Thanks, I created a new class based in the GMapMarkerTransparentGoogleGreen, which accepts a few parameters. This did the trick, all PNG's are now shown correctly with the transparent background!