packages/Windows API Code Pack 1.1/source/Samples/Shell/StarBackupUsingLibraries/CS/StarBackupHelper.cs
/// <summary>
/// Resize a given image using the new width/height
/// </summary>
/// <param name="source"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
Resize a given image using the new width/height
Resize a given image using the new width / height
public static ImageSource CreateResizedImage(ImageSource source, int width, int height)
        {
            Rect rect = new Rect(0, 0, width, height);
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawImage(source, rect);
            }
            RenderTargetBitmap resizedImage = new RenderTargetBitmap(
                (int)rect.Width, (int)rect.Height,  
                96, 96,                             
                PixelFormats.Default);              
            resizedImage.Render(drawingVisual);
            return resizedImage;
        }
public static ImageSource CreateResizedImage ( ImageSource source , int width , int height ) { Rect rect = new Rect ( 0 , 0 , width , height ) ; DrawingVisual drawingVisual = new DrawingVisual ( ) ; using ( DrawingContext drawingContext = drawingVisual . RenderOpen ( ) ) { drawingContext . DrawImage ( source , rect ) ; } RenderTargetBitmap resizedImage = new RenderTargetBitmap ( ( int ) rect . Width , ( int ) rect . Height , 96 , 96 , PixelFormats . Default ) ; resizedImage . Render ( drawingVisual ) ; return resizedImage ; }
Resize a given image using the new width/height
Resize a given image using the new width / height
// Target Rect for the resize operation // Create a DrawingVisual/Context to render with // Use RenderTargetBitmap to resize the original image // Resized dimensions // Default DPI values // Default pixel format // Return the resized image
None
source
ImageSource
None
width
int
None
height
int
None