public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { // see: http://stackoverflow.com/questions/152729/gdi-c-how-to-save-an-image-as-emf string filename = FileDialog.ShowSave(FileDialog.Context.Image, "*.emf|*.emf"); if (String.IsNullOrEmpty(filename)) { return; } Image objImage = pnlView.CreateImage(true, true, false); IntPtr h = ((Metafile)objImage).GetHenhmetafile(); Windows.ClipboardMetafileHelper.CopyEnhMetaFileW(h, filename); Windows.ClipboardMetafileHelper.DeleteEnhMetaFile(h); objImage.Dispose(); }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { string filename = FileDialog.ShowSave(FileDialog.Context.Image, "*." + extension + "|*." + extension); if (string.IsNullOrEmpty(filename)) { return; } const bool selection = false; // was param before, not sure if true was ever used? Image image = pnlView.CreateImage(false, !selection, selection); if (File.Exists(filename)) { File.Delete(filename); } image.Save(filename, format); image.Dispose(); }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { if (CurrentPage == null || CurrentPage.SelectedCount == 0) { return; } // the items to put on the clipboard // even if cutting, we put a different copy of the objects on the clipboard with different IDs (in case the user undoes which would restore the original objects) DatumList hash = Datum.CloneList(CurrentPage.SelectedShapes, Globals.Root.CurrentDocument); // copies shapes, changes IDs, updates links and includes references as needed // write the list of shapes into a byte buffer; this way we control the serialisation DataObject data = new DataObject(); using (MemoryStream buffer = new MemoryStream(1000)) { using (DataWriter writer = new DataWriter(buffer, FileMarkers.ShapeList)) { List <Datum> list = new List <Datum>(); list.AddRange(hash.Values); writer.WriteDatumList(list); data.SetData("Splash data", false, buffer.GetBuffer()); } } Bitmap bitmap = (Bitmap)pnlView.CreateImage(false, false, true); // will have white background - transparent gets lost somewhere within clipboard data.SetImage(bitmap); //objBitmap.Dispose()' doesn't work if this done // http://stackoverflow.com/questions/35045500/copy-svg-image-stored-as-xml-string-to-windows-clipboard-as-image-svgxml-mime-t try { var strSVG = pnlView.CreateSVG(false, true); // True) byte[] aBytes = Encoding.UTF8.GetBytes(strSVG); MemoryStream objStream = new MemoryStream(aBytes); data.SetData("image/svg+xml", objStream); //System.IO.File.WriteAllText("g:\temp\svg.svg", strSVG) } catch (UserException u) { Globals.Root.Log.WriteLine("Cannot copy as SVG: " + u.Message); } catch (Exception ex) { Utilities.LogSubError(ex); } //check for text string text = ""; foreach (Shape shape in CurrentPage.SelectedShapes) { if (shape.HasText(true) && !String.IsNullOrEmpty(shape.LabelText)) { text = shape.LabelText; break; // stop once valid text found } } if (!string.IsNullOrEmpty(text)) { data.SetText(text); } // store result on clipboard Clipboard.SetDataObject(data); if (IsCut) { CurrentPage.DeleteSelected(transaction); } }