Example #1
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);
            }
        }