コード例 #1
0
        private static bool ExportToImage(string path)
        {
            bool result = true;

            ClickData.Clear(true);

            Canvas canvas = Canvas.Instance;

            // Hide borders when saving image
            var prevBorder = canvas.BorderStyle;

            canvas.BorderStyle = BorderStyle.None;
            IsExportingImage   = true;
            canvas.Invalidate();

            var bounds = canvas.layer.GetAllShapesBoundary();

            ImageFormat imageFormat = Utils.GetImageFormatByExtension(path);

            if (bounds.Width == 0 && bounds.Height == 0)
            {
                MessageBox.Show("Nothing to save. Try placing some shapes before exporting to image.");
                result = false;
            }
            using (var bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                canvas.DrawToBitmap(bitmap, bounds);
                bitmap.Save(path, imageFormat);
            }

            // Restore border
            canvas.BorderStyle = prevBorder;
            IsExportingImage   = false;
            canvas.Invalidate();

            return(result);
        }