internal static MemoryStream SaveImage(BitmapSource bitmapSource, string imageContentType) { MemoryStream memoryStream = new MemoryStream(); WpfPayload wpfPayload = new WpfPayload(null); using (wpfPayload.CreatePackage(memoryStream)) { int imageIndex = 0; string imageReference = WpfPayload.GetImageReference(WpfPayload.GetImageName(imageIndex, imageContentType)); PackagePart packagePart = wpfPayload.CreateWpfEntryPart(); Stream stream = packagePart.GetStream(); using (stream) { StreamWriter streamWriter = new StreamWriter(stream); using (streamWriter) { string value = string.Concat(new object[] { "<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><InlineUIContainer><Image Width=\"", bitmapSource.Width, "\" Height=\"", bitmapSource.Height, "\" ><Image.Source><BitmapImage CacheOption=\"OnLoad\" UriSource=\"", imageReference, "\"/></Image.Source></Image></InlineUIContainer></Span>" }); streamWriter.Write(value); } } wpfPayload.CreateImagePart(packagePart, bitmapSource, imageContentType, imageIndex); } return(memoryStream); }
/// <summary> /// Saves the content of the range in the given stream as a WPF payload. /// </summary> /// <param name="range"> /// The range whose content is to be serialized. /// </param> /// <param name="stream"> /// When the stream is not null, it is a request to unconditionally /// creatte WPF package in this stream. /// If this parameter is null, then the package is created /// only when necessary - when there are images in the range. /// The new MemoryStream is created in this case and assigned to this /// parameter on exit. /// </param> /// <param name="useFlowDocumentAsRoot"> /// </param> /// <param name="preserveTextElements"> /// If set false, custom TextElements will be upcasted to known types. /// </param> /// <returns> /// A xaml part of serialized content. /// </returns> internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements) { if (range == null) { throw new ArgumentNullException("range"); } // Create the wpf package in the stream WpfPayload wpfPayload = new WpfPayload(/*package:*/ null); // Create a string representing serialized xaml StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements); string xamlText = stringWriter.ToString(); // Decide whether we need to create a package if (stream != null || wpfPayload._images != null) { // There are images in the content. Need to create a package if (stream == null) { stream = new MemoryStream(); } // Create a package in the stream using (wpfPayload.CreatePackage(stream)) { // Create the entry part for xaml content of the WPF package PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart(); // Write the part's content Stream xamlPartStream = xamlEntryPart.GetStream(); using (xamlPartStream) { StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream); using (xamlPartWriter) { xamlPartWriter.Write(xamlText); } } // Write relationships from xaml entry part to all images wpfPayload.CreateComponentParts(xamlEntryPart); } Invariant.Assert(wpfPayload._images == null); // must have beed cleared in CreateComponentParts } return(xamlText); }
internal static MemoryStream SaveImage(BitmapSource bitmapSource, string imageContentType) { MemoryStream stream = new MemoryStream(); // Create the wpf package in the stream WpfPayload wpfPayload = new WpfPayload(/*package:*/ null); // Create a package in the stream using (wpfPayload.CreatePackage(stream)) { // Define a reference for the image int imageIndex = 0; string imageReference = GetImageReference(GetImageName(imageIndex, imageContentType)); // Create the entry part for xaml content of the WPF package PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart(); // Write the part's content Stream xamlPartStream = xamlEntryPart.GetStream(); using (xamlPartStream) { StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream); using (xamlPartWriter) { string xamlText = "<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" + "<InlineUIContainer><Image " + "Width=\"" + bitmapSource.Width + "\" " + "Height=\"" + bitmapSource.Height + "\" " + "><Image.Source><BitmapImage CacheOption=\"OnLoad\" UriSource=\"" + imageReference + "\"/></Image.Source></Image></InlineUIContainer></Span>"; xamlPartWriter.Write(xamlText); } } // Add image to a package wpfPayload.CreateImagePart(xamlEntryPart, bitmapSource, imageContentType, imageIndex); } return(stream); }
// Token: 0x06003F1E RID: 16158 RVA: 0x0012055C File Offset: 0x0011E75C internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements) { if (range == null) { throw new ArgumentNullException("range"); } WpfPayload wpfPayload = new WpfPayload(null); StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements); string text = stringWriter.ToString(); if (stream != null || wpfPayload._images != null) { if (stream == null) { stream = new MemoryStream(); } using (wpfPayload.CreatePackage(stream)) { PackagePart packagePart = wpfPayload.CreateWpfEntryPart(); Stream stream2 = packagePart.GetStream(); using (stream2) { StreamWriter streamWriter = new StreamWriter(stream2); using (streamWriter) { streamWriter.Write(text); } } wpfPayload.CreateComponentParts(packagePart); } Invariant.Assert(wpfPayload._images == null); } return(text); }
internal static MemoryStream SaveImage(BitmapSource bitmapSource, string imageContentType) { MemoryStream stream = new MemoryStream(); // Create the wpf package in the stream WpfPayload wpfPayload = new WpfPayload(/*package:*/null); // Create a package in the stream using (wpfPayload.CreatePackage(stream)) { // Define a reference for the image int imageIndex = 0; string imageReference = GetImageReference(GetImageName(imageIndex, imageContentType)); // Create the entry part for xaml content of the WPF package PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart(); // Write the part's content Stream xamlPartStream = xamlEntryPart.GetStream(); using (xamlPartStream) { StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream); using (xamlPartWriter) { string xamlText = "<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" + "<InlineUIContainer><Image " + "Width=\"" + bitmapSource.Width + "\" " + "Height=\"" + bitmapSource.Height + "\" " + "><Image.Source><BitmapImage CacheOption=\"OnLoad\" UriSource=\"" + imageReference + "\"/></Image.Source></Image></InlineUIContainer></Span>"; xamlPartWriter.Write(xamlText); } } // Add image to a package wpfPayload.CreateImagePart(xamlEntryPart, bitmapSource, imageContentType, imageIndex); } return stream; }
/// <summary> /// Saves the content of the range in the given stream as a WPF payload. /// </summary> /// <param name="range"> /// The range whose content is to be serialized. /// </param> /// <param name="stream"> /// When the stream is not null, it is a request to unconditionally /// creatte WPF package in this stream. /// If this parameter is null, then the package is created /// only when necessary - when there are images in the range. /// The new MemoryStream is created in this case and assigned to this /// parameter on exit. /// </param> /// <param name="useFlowDocumentAsRoot"> /// </param> /// <param name="preserveTextElements"> /// If set false, custom TextElements will be upcasted to known types. /// </param> /// <returns> /// A xaml part of serialized content. /// </returns> internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements) { if (range == null) { throw new ArgumentNullException("range"); } // Create the wpf package in the stream WpfPayload wpfPayload = new WpfPayload(/*package:*/null); // Create a string representing serialized xaml StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements); string xamlText = stringWriter.ToString(); // Decide whether we need to create a package if (stream != null || wpfPayload._images != null) { // There are images in the content. Need to create a package if (stream == null) { stream = new MemoryStream(); } // Create a package in the stream using (wpfPayload.CreatePackage(stream)) { // Create the entry part for xaml content of the WPF package PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart(); // Write the part's content Stream xamlPartStream = xamlEntryPart.GetStream(); using (xamlPartStream) { StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream); using (xamlPartWriter) { xamlPartWriter.Write(xamlText); } } // Write relationships from xaml entry part to all images wpfPayload.CreateComponentParts(xamlEntryPart); } Invariant.Assert(wpfPayload._images == null); // must have beed cleared in CreateComponentParts } return xamlText; }