コード例 #1
0
        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);
        }
コード例 #2
0
        // Token: 0x06003F2C RID: 16172 RVA: 0x00120E4C File Offset: 0x0011F04C
        internal Stream CreateImageStream(int imageCount, string contentType, out string imagePartUriString)
        {
            imagePartUriString = WpfPayload.GetImageName(imageCount, contentType);
            Uri         partUri     = new Uri("/Xaml" + imagePartUriString, UriKind.Relative);
            PackagePart packagePart = this._package.CreatePart(partUri, contentType, CompressionOption.NotCompressed);

            imagePartUriString = WpfPayload.GetImageReference(imagePartUriString);
            return(packagePart.GetStream());
        }
コード例 #3
0
        private void CreateImagePart(PackagePart sourcePart, BitmapSource imageSource, string imageContentType, int imageIndex)
        {
            string              imageName           = WpfPayload.GetImageName(imageIndex, imageContentType);
            Uri                 uri                 = new Uri("/Xaml" + imageName, UriKind.Relative);
            PackagePart         packagePart         = this._package.CreatePart(uri, imageContentType, CompressionOption.NotCompressed);
            PackageRelationship packageRelationship = sourcePart.CreateRelationship(uri, TargetMode.Internal, "http://schemas.microsoft.com/wpf/2005/10/xaml/component");
            BitmapEncoder       bitmapEncoder       = WpfPayload.GetBitmapEncoder(imageContentType);

            bitmapEncoder.Frames.Add(BitmapFrame.Create(imageSource));
            Stream stream = packagePart.GetStream();

            using (stream)
            {
                bitmapEncoder.Save(stream);
            }
        }
コード例 #4
0
        // Token: 0x06003F26 RID: 16166 RVA: 0x00120A2C File Offset: 0x0011EC2C
        internal string AddImage(Image image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (image.Source == null)
            {
                throw new ArgumentNullException("image.Source");
            }
            if (string.IsNullOrEmpty(image.Source.ToString()))
            {
                throw new ArgumentException(SR.Get("WpfPayload_InvalidImageSource"));
            }
            if (this._images == null)
            {
                this._images = new List <Image>();
            }
            string text             = null;
            string imageContentType = WpfPayload.GetImageContentType(image.Source.ToString());

            for (int i = 0; i < this._images.Count; i++)
            {
                if (WpfPayload.ImagesAreIdentical(this.GetBitmapSourceFromImage(this._images[i]), this.GetBitmapSourceFromImage(image)))
                {
                    Invariant.Assert(imageContentType == WpfPayload.GetImageContentType(this._images[i].Source.ToString()), "Image content types expected to be consistent: " + imageContentType + " vs. " + WpfPayload.GetImageContentType(this._images[i].Source.ToString()));
                    text = WpfPayload.GetImageName(i, imageContentType);
                }
            }
            if (text == null)
            {
                text = WpfPayload.GetImageName(this._images.Count, imageContentType);
                this._images.Add(image);
            }
            return(WpfPayload.GetImageReference(text));
        }