ThinkGeo.com    |     Documentation    |     Premium Support

Save map as an image using GeoCanvas issue

Hi,
I am trying to Save Map using GeoCanvas. But Aircraft image saving as below of the Route.

Please check snapshot.

Code:
private void ExportSatelliteImage()
{
try
{
GeoCanvas myCanvas = null;
Collection labelsInLayers = new Collection();
Bitmap myImage = new Bitmap((int)wfMap.Width, (int)wfMap.Height);
myCanvas = new GdiPlusGeoCanvas();
myCanvas.BeginDrawing(myImage, wfMap.CurrentExtent, wfMap.MapUnit);
int c = 0;
foreach (LayerOverlay layeroverlay in wfMap.Overlays)
{
if (wfMap.Overlays[c].IsVisible)
{
foreach (Layer layer in layeroverlay.Layers)
{
layer.Open();
layer.Draw(myCanvas, labelsInLayers);
layer.Close();
}
}
else
{
c = c + 1;
continue;
}
c = c + 1;
}
myCanvas.EndDrawing();
myImage.Save(@“F:\GlobalSatellite.png”, System.Drawing.Imaging.ImageFormat.Png);
}
catch (Exception ex)
{
}
finally
{
}
}

Aircraft Layer adding in the last, even though it’s not getting top of the image.
I tried with MoveToTop for aircraft overlay top. But not work out.
Please suggest me some logic for resolve this issue.

Thanks,
Riyaz

Hi Riyas,

I cannot reproduce it without your layers, but I think you can solve that like this.

At first please add a breakpoint here:

foreach (Layer layer in layeroverlay.Layers)
{
layer.Open();
layer.Draw(myCanvas, labelsInLayers);
layer.Close();
}

And you can check whether your Aircraft Layer is the last one which is drawn to canvas. If it’s not the last one, just adjust the loop order.

If it’s the last one but the result is still incorrect, you can ignore this layer in the loop. After export the result into an image(in memory), then create a new canvas based on the image and draw based on it for the layer.

I think you can solve it follow this way.

Regards,

Ethan

Hi Ethan,
Thanks it’s work out.

Regards,
Riyaz

Hi Riyaz,

I am glad to hear that’s helpful.

Regards,

Ethan