コード例 #1
0
        public static Stream CroppedBitmapToPngStream(this CroppedBitmap image)
        {
            MemoryStream     memStream = new MemoryStream();
            PngBitmapEncoder encoder   = new PngBitmapEncoder();

            var frame = encoder.With(x => image)
                        .With(x => BitmapFrame.Create(x));

            if (frame == null)
            {
                return(null);
            }

            encoder.Frames.Add(frame);
            encoder.Save(memStream);
            return(memStream);
        }
コード例 #2
0
        public static Stream ToPngStream(this System.Windows.Controls.Image image)
        {
            if (image == null || image.Source == null)
            {
                return(null);
            }

            MemoryStream     memStream = new MemoryStream();
            PngBitmapEncoder encoder   = new PngBitmapEncoder();

            var frame = encoder.With(x => image.Source as CroppedBitmap)
                        .With(x => BitmapFrame.Create(x));

            if (frame == null)
            {
                return(null);
            }

            encoder.Frames.Add(frame);
            encoder.Save(memStream);
            return(memStream);
        }