Пример #1
0
        public void SaveMapAsJPEG(string filename)
        {
            var gdalUtils = new GdalUtils();

            PrintCallback callback = new PrintCallback(MapControlTools);

            gdalUtils.GlobalCallback = callback;

            var image = AxMap.SnapShot(AxMap.Extents);

            image.Save(filename, true, ImageType.JPEG_FILE);
        }
Пример #2
0
        public void CaptureSnapshot()
        {
            // clear map
            _axMap1.ClearDrawings();
            _axMap1.RemoveAllLayers();
            // create layer
            CreateLayer();

            //
            var bpp = Screen.PrimaryScreen.BitsPerPixel;

            DebugMsg($"Current color depth is {bpp} bits per pixel");
            // test is only valid when not in 32 bit color depth
            if (bpp == 32)
            {
                DebugMsg("  Test is only valid for color depth less than 32 bpp");
            }
            try
            {
                DebugMsg("Calling AxMap.Snapshot() method.  Watch for Access Violation Exception if color depth is less than 32 bpp.");
                var img = _axMap1.SnapShot(_axMap1.Extents);
                Assert.IsNotNull(img, "axMap1.SnapShot returned null");
                DebugMsg($"Successfully called Snapshot() with color depth = {bpp}.");
                if (bpp != 32)
                {
                    DebugMsg("  Test verified.");
                }
            }
            catch (AccessViolationException avex)
            {
                Assert.Fail(avex.ToString());
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Пример #3
0
        public static string SaveSnapshot(AxMap axMap1, string baseName, IExtents boundBox, double extentEnlarger = 1d)
        {
            Application.DoEvents();
            var filename = Path.Combine(Path.GetTempPath(), baseName);

            DeleteFile(filename);

            if ((boundBox.Width * boundBox.Height).Equals(0))
            {
                double xmin, ymin, xmax, ymax, zmin, zmax;
                boundBox.GetBounds(out xmin, out ymin, out zmin, out xmax, out ymax, out zmax);
                boundBox.SetBounds(xmin - extentEnlarger, ymin - extentEnlarger, zmin, xmax + extentEnlarger, ymax + extentEnlarger, zmax);
            }

            var img = axMap1.SnapShot(boundBox);

            if (img == null)
            {
                throw new NullReferenceException("Snapshot is null: " + axMap1.get_ErrorMsg(axMap1.LastErrorCode));
            }

            var retVal = img.Save(filename);

            img.Close();
            img = null;
            if (!retVal)
            {
                throw new Exception("Snapshot could not be saved: " + img.ErrorMsg[img.LastErrorCode]);
            }
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("The file doesn't exists.", filename);
            }
            DebugMsg(filename);

            return(filename);
        }