ThinkGeo.com    |     Documentation    |     Premium Support

Saving overlayed Raster Image into Local

Hi,

I am using NativeImageRasterLayer to Overlay my satellite image on Top of World map… And its doing fine.

But from the application I am trying Save that overlayed image on Right click -> Save image as , to my Local, but I can’t able to do it… Please look my code and snapshot below…

LayerOverlay SatelliteOverlay = (LayerOverlay)wfMap.CustomOverlays[“Satellite1”];

NativeImageRasterLayer rasterSatelliteLayer = new NativeImageRasterLayer(_sMapDataPath + @"\MapData\WxCharts\HSDGSAT" + sSatelliteDownloadImage, _proj.ConvertToExternalProjection(new RectangleShape(-179.999979224, 79.9899914532, 179.972976801, -50.0233908027)));
rasterSatelliteLayer.Transparency = 200;
SatelliteOverlay.IsVisible = true;
SatelliteOverlay.Layers.Add(“SatelliteColorlayer”, rasterSatelliteLayer);

But I am unable to save it to local… Please guide me how to do it…

Thank you,
Ashok

Hi Ashok,

When you click the “Save Image As” button in context menu, you can see it’s a .axd file, but in fact it’s an image, you can modify the suffix name to make it valid for your computer.

And maybe you will found it’s only a tile image, you can try to get an entire image by single tile mode.

And we have a sever side API GetBitmap, you can write custom function to call this API, and get entire image then download it by your JavaScript code.

Regards,

Ethan

Hi Ethan,

Thanks for your reply. I didn’t see any .axd file, Once I right click --> Save Image as–> I am able to save as .png itself. The file name is tile_GeoResource.png . But it is able to save only flights on map.
The image which i saved is follows.

But i wanted to save Overlayed Satellite image without any background.

You have talked about “sever side API GetMapImage”. But I think it will save along with background map. But I need only Satellite image which I overlayed.

Please do needful

Thanks,
Ashok

Hi Ashok,

It looks the flights layer cover the entire map, so you cannot save the background layer.

So I think you still need to write custom JavaScript function to require the image from server side, and save the image into local machine.

As below is the code for help you draw your layer in server side, wish that’s helpful.

 public Bitmap GetBitmap(int width, int height)
    {
        Bitmap bitmap = new Bitmap(map.MapWidth, map.MapHeight);

        PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas();
        
        foreach (Overlay overlay in map.CustomOverlays)
        {
            LayerOverlay customLayerOverlay = overlay as LayerOverlay;

            // Find your overlay which contains your rasterSatelliteLayer

            if (customLayerOverlay != null && !customLayerOverlay.IsBaseOverlay)
            {
                customLayerOverlay.Draw(geoCanvas, bitmap, CurrentExtent, MapUnit);
            }
        }

        if (bitmap.Width != width && bitmap.Height != height)
        {
            Rectangle srcRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            Rectangle destRect = new Rectangle(0, 0, width, height);
            Bitmap destBitmap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(destBitmap);
            g.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
            bitmap.Dispose();
            bitmap = destBitmap;
        }

        return bitmap;
    }

Regards,

Ethan

Hi Ethan,

Thank you for the code given. It is working out…

Actually I was wrong. I wanted to save or print entire map (not just Satellite image).

I used your code. and gone through all the overlays and draw. Map is saving but only problem is can’t able to draw map’s background color. It is coming as Black color. shown below.

please help me in how to bring background also.

Thanks,
Ashok

Hi Ashok,

You can call this code to draw background color:

geoCanvas.BeginDrawing(bitmap, CurrentExtent, mapUnit);
geoCanvas.Clear(mapBackground);
geoCanvas.EndDrawing();

And if you want to draw other overlay, just loop them and draw them into the canvas.

If you want to draw everything, please call the API GetBitmap directly.

Regards,

Ethan

Thank you so much Ethan. Its working… :smile:

Hi Ashok,

I am glad to hear that works.

Regards,

Ethan