Beispiel #1
0
        // TODO: Need to add support for delayed rendering
        public void SetClipboardData(IOrderedDictionary <string, MemoryStream> data)
        {
            try
            {
                _clipboardHelper.OpenClipboard();
                _clipboardHelper.EmptyClipboard();

                var formats       = new OrderedDictionary <string, int>();
                var clipboardData = new Dictionary <string, MemoryStream>();
                foreach (var format in data)
                {
                    var dataFormat = DataFormats.GetDataFormat(format.Key);
                    try
                    {
                        _clipboardHelper.SetClipboardData(dataFormat.Id, format.Value);

                        // Store format names as lowercase
                        formats[format.Key.ToLower()]       = dataFormat.Id;
                        clipboardData[format.Key.ToLower()] = format.Value;
                    }
                    catch
                    {
                        // Do nothing
                    }
                }

                _formats        = formats;
                _formatsCurrent = true;
                _clipboardData  = clipboardData;
            }
            finally
            {
                _clipboardHelper.CloseClipboard();
            }
        }
Beispiel #2
0
        private void ExportImage()
        {
            // Update file extension
            if (string.IsNullOrEmpty(Path.GetExtension(_filePath)))
            {
                SetFilePath(_filePath + GetFileExtension(_imageFormat));
            }
            // Check if the file path changed since last export
            if (_filePathChanged && !CanOverwriteFile(_filePath))
            {
                return;
            }

            if (_image == null)
            {
                CreateImage();
            }
            if (_image != null)
            {
                switch (_imageFormat)
                {
                case ImageFileFormat.Emf:
                case ImageFileFormat.EmfPlus:
                    if (_exportToClipboard)
                    {
                        try {
                            ClipboardHelper.OpenClipboard(this.Handle);
                            ClipboardHelper.EmptyClipboard();
                            ClipboardHelper.AddEnhMetafileToClipboard((Metafile)_image.Clone());
                        } finally {
                            ClipboardHelper.CloseClipboard();
                        }
                    }
                    else
                    {
                        GdiHelpers.SaveImage(_image, _filePath, _imageFormat, _compressionQuality);
                    }
                    break;

                case ImageFileFormat.Bmp:
                case ImageFileFormat.Gif:
                case ImageFileFormat.Jpeg:
                case ImageFileFormat.Png:
                case ImageFileFormat.Tiff:
                    if (_exportToClipboard)
                    {
                        Clipboard.SetImage((Image)_image.Clone());
                    }
                    else
                    {
                        GdiHelpers.SaveImage(_image, _filePath, _imageFormat, _compressionQuality);
                    }
                    break;

                case ImageFileFormat.Svg:
                    throw new NotImplementedException();

                default: throw new NShapeUnsupportedValueException(_imageFormat);
                }
            }
            _filePathChanged = false;
        }