예제 #1
0
        public static byte[] GetImageBytesFromSketch(Sketch sketch)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                SaveSketchToImageStream(sketch, stream);
                stream.Seek(0, SeekOrigin.Begin);

                return stream.GetBuffer();
            }
        }
예제 #2
0
        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;
        }
예제 #3
0
        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();
        }
예제 #4
0
        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;
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
                }
            }
        }