/// <summary> /// Writes the specified image. /// </summary> /// <param name="x">The x-coordinate.</param> /// <param name="y">The y-coordinate.</param> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="image">The image.</param> public void WriteImage(double x, double y, double width, double height, OxyImage image) { // http://www.w3.org/TR/SVG/shapes.html#ImageElement this.WriteStartElement("image"); this.WriteAttributeString("x", x); this.WriteAttributeString("y", y); this.WriteAttributeString("width", width); this.WriteAttributeString("height", height); this.WriteAttributeString("preserveAspectRatio", "none"); var imageData = image.GetData(); var encodedImage = new StringBuilder(); encodedImage.Append("data:"); encodedImage.Append("image/png"); encodedImage.Append(";base64,"); encodedImage.Append(Convert.ToBase64String(imageData)); this.WriteAttributeString("xlink", "href", null, encodedImage.ToString()); this.WriteEndElement(); }
/// <summary> /// Loads the image from the specified source. /// </summary> /// <param name="source">The image source.</param> /// <returns>A <see cref="Image" />.</returns> private Image GetImage(OxyImage source) { if (source == null) { return null; } if (!this.imagesInUse.Contains(source)) { this.imagesInUse.Add(source); } Image src; if (this.imageCache.TryGetValue(source, out src)) { return src; } Image btm; using (var ms = new MemoryStream(source.GetData())) { btm = Image.FromStream(ms); } this.imageCache.Add(source, btm); return btm; }
/// <summary> /// Writes the specified image. /// </summary> /// <param name="x">The x-coordinate.</param> /// <param name="y">The y-coordinate.</param> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="image">The image.</param> public void WriteImage(double x, double y, double width, double height, OxyImage image) { // http://www.w3.org/TR/SVG/shapes.html#ImageElement this.WriteStartElement("image"); this.WriteAttributeString("x", x); this.WriteAttributeString("y", y); this.WriteAttributeString("width", width); this.WriteAttributeString("height", height); this.WriteAttributeString("preserveAspectRatio", "none"); var imageData = image.GetData(); var encodedImage = new StringBuilder(); encodedImage.Append("data:"); encodedImage.Append("image/png"); encodedImage.Append(";base64,"); encodedImage.Append(Convert.ToBase64String(imageData)); this.WriteAttributeString("xlink", "href", null, encodedImage.ToString()); this.WriteClipPathAttribute(); this.WriteEndElement(); }