示例#1
0
        public static ImageSource Resize(this ImageSource image, Size maxSize)
        {
            var rasterImage = ToRasterImage(image);
            var currentSize = new Size(rasterImage.ImageSize.Width, rasterImage.ImageSize.Height);
            var newSize = currentSize.PreserveAspectRatioWithinBounds(maxSize);

            var destImage = new RasterImage(
                RasterMemoryFlags.Conventional,
                (int)newSize.Width,
                (int)newSize.Height,
                rasterImage.BitsPerPixel,
                rasterImage.Order,
                rasterImage.ViewPerspective,
                rasterImage.GetPalette(),
                IntPtr.Zero,
                0);

            var cmd = new ResizeCommand(destImage, RasterSizeFlags.Bicubic);
            cmd.Run(rasterImage);
            return ToBitmapSource(destImage);
        }