How to resize an Image C#

前端 未结 17 2753
暗喜
暗喜 2020-11-21 22:28

As Size, Width and Height are Get() properties of System.Drawing.Image;
How can I resize an Image object

17条回答
  •  佛祖请我去吃肉
    2020-11-21 23:24

    Why not use the System.Drawing.Image.GetThumbnailImage method?

    public Image GetThumbnailImage(
        int thumbWidth, 
        int thumbHeight, 
        Image.GetThumbnailImageAbort callback, 
        IntPtr callbackData)
    

    Example:

    Image originalImage = System.Drawing.Image.FromStream(inputStream, true, true);
    Image resizedImage = originalImage.GetThumbnailImage(newWidth, (newWidth * originalImage.Height) / originalWidth, null, IntPtr.Zero);
    resizedImage.Save(imagePath, ImageFormat.Png);
    

    Source: http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx

提交回复
热议问题