public static byte[] GetImageBytesFromSketch(Sketch sketch) { using (MemoryStream stream = new MemoryStream()) { SaveSketchToImageStream(sketch, stream); stream.Seek(0, SeekOrigin.Begin); return stream.GetBuffer(); } }
public static Sketch GetSketchFromXmlData(string xmlData) { StringReader stringReader; Sketch sketch; if (DataTypeFascade.Instance.IsNullOrWhiteSpace(xmlData)) sketch = new Sketch(); else { stringReader = new StringReader(xmlData); sketch = LoadFrom(stringReader); } return sketch; }
public void SetSketch(Sketch sketch) { this.Sketch = sketch; foreach (ToolBarButton tbBtn in this.tbarTools.Buttons) tbBtn.Enabled = (object)this.Sketch != null; this.pnlCanvas.Enabled = (object)this.Sketch != null; this.pnlCanvas.Refresh(); }
public static string GetXmlDataFromSketch(Sketch sketch) { string xmlData; StringWriter stringWriter; if ((object)sketch == null) return null; stringWriter = new StringWriter(); SaveTo(sketch, stringWriter); xmlData = stringWriter.ToString(); return xmlData; }
public static void SaveToFile(Sketch sketch, string filePath) { if ((object)sketch == null) throw new ArgumentNullException("sketch"); if ((object)filePath == null) throw new ArgumentNullException("filePath"); if (DataTypeFascade.Instance.IsNullOrWhiteSpace(filePath)) throw new ArgumentOutOfRangeException("filePath"); using (Stream stream = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { using (StreamWriter streamWriter = new StreamWriter(stream)) SaveTo(sketch, streamWriter); } }
public static void SaveTo(Sketch sketch, TextWriter textWriter) { XmlSerializer xmlSerializer; if ((object)sketch == null) throw new ArgumentNullException("sketch"); if ((object)textWriter == null) throw new ArgumentNullException("textWriter"); xmlSerializer = new XmlSerializer(typeof(Sketch), SketchFactory.KnownTypes); xmlSerializer.Serialize(textWriter, sketch); }
public static void SaveSketchToImageStream(Sketch sketch, Stream stream) { int width = 0, height = 0; Size extent; if ((object)sketch == null) throw new ArgumentNullException("sketch"); if ((object)stream == null) throw new ArgumentNullException("stream"); foreach (SketchShape shape in sketch.Shapes) { extent = shape.GetExtent(); width = Math.Max(width, extent.Width); height = Math.Max(height, extent.Height); } width = Math.Max(width, 1); height = Math.Max(height, 1); using (Image image = new Bitmap(width, height)) { using (Graphics graphics = Graphics.FromImage(image)) { sketch.RenderToSurface(graphics); image.Save(stream, ImageFormat.Png); } } }