ThinkGeo.com    |     Documentation    |     Premium Support

DrawToBitmap Resolution

Hi,

I am drawing a map control in the background and using map.DrawToBitmap to save to an image; however, it doesn’t seem to matter how big I make the bitmap and the associated map control. After it goes through DrawToBitmap, the image is automatically reduced to 1828x1228 pixels and is too low res.

Any ideas how to get it to accept the input bitmap size?

I am setting the map control height and width to the same as my bitmap and I am also setting the extents of my map to the required data before refresh and save to bitmap.

Thanks,
Damian

Damian,
map.DrawToBitmap is kind of like do a screenshot for the map control. I would recommend use the GeoCanvas.

Here is the sample code

   GeoImage bitmap = new GeoImage(4000, 2000);
            ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(Application.StartupPath +  @"\Shapefile\Countries02.shp");
                    layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColor.FromArgb(255, 169, 195, 221), 2F, GeoColors.Black, 4F, false);
            layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 233, 232, 214), GeoColor.FromArgb(255, 156, 155, 154), 1);
            layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            layer.Open();

            RectangleShape extent = layer.GetBoundingBox();
            GeoCanvas canvas = GeoCanvas.CreateDefaultGeoCanvas();
            canvas.BeginDrawing(bitmap, extent, GeographyUnit.DecimalDegree);
            layer.Draw(canvas, new Collection<SimpleCandidate>());
            canvas.EndDrawing();
            var executingFolderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            bitmap.Save($@"{executingFolderPath}\Jpeg2000Test.png");

You can draw all layers to the same canvas. And then save the bitmap.

Thanks

Frank

Hi Frank,

Thanks, you put me on the right track, but I had some issue implementing your code.

I found that GeoImage in v10 doesn’t have a Save function. So, I changed GeoCanvas to PlatformGeoCanvas which allowed me to draw directly to a bitmap like so.

        using (Bitmap bitmap = new Bitmap(w, h))
        {
            PlatformGeoCanvas canvas = new PlatformGeoCanvas();
            canvas.BeginDrawing(bitmap, rect, GeographyUnit.Meter);
            imfl.Draw(canvas, new Collection<SimpleCandidate>());
            canvas.EndDrawing();
            bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
        }

Resolution looking good now.

Thanks,
Damian

Thanks Damian,
Good to know it works. Go ahead let us know if you have any more questions.

Thanks

Frank