コード例 #1
0
ファイル: CustomChart.cs プロジェクト: m-kosina/GEDKeeper
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = FileHelper.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if (ext == ".svg")
            {
                var prevRenderer = fRenderer;
                SetRenderer(new SVGRenderer(fileName, imageSize.Width, imageSize.Height));
                fRenderer.BeginDrawing();
                try {
                    using (var gfx = CreateGraphics()) {
                        fRenderer.SetTarget(gfx);

                        RenderImage(RenderTarget.SVG);
                    }
                } finally {
                    fRenderer.EndDrawing();
                    SetRenderer(prevRenderer);
                }

                return;
            }

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bitmap;
                }
                else if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                } /*else if (ext == ".emf") {
                   * imFmt = ImageFormat.Emf;
                   * }*/

                /*Image pic;
                 * if (Equals(imFmt, ImageFormat.Emf)) {
                 *  using (var gfx = CreateGraphics()) {
                 *      pic = new Metafile(fileName, gfx.GetHdc());
                 *  }
                 * } else {
                 *  pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                 * }*/

                Bitmap pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                try {
                    using (Graphics gfx = new Graphics(pic)) {
                        fRenderer.SetTarget(gfx);
                        RenderImage(RenderTarget.RasterFile);
                    }

                    pic.Save(fileName, imFmt);
                } finally {
                    pic.Dispose();
                }
            }
        }