2012-06-22 75 views

回答

0

您可以使用WIC(Windows Imaging Component)而不是GDI +。下面是一個例子nice blog post

0

首先轉換您BitmapImage

Bitmap b = new Bitmap("asdf.jpg"); 
Image i = (Image)b; 

然後將圖像傳遞給此方法來調整

public static Image ResizeImage(Image image, int width, int height, bool onlyResizeIfWider) 
{ 
    using (image) 
    { 
     // Prevent using images internal thumbnail. 
     image.RotateFlip(RotateFlipType.Rotate180FlipNone); 
     image.RotateFlip(RotateFlipType.Rotate180FlipNone); 

     if (onlyResizeIfWider == true) 
      if (image.Width <= width) 
       width = image.Width; 

     // Resize with height instead? 
     int newHeight = image.Height * width/image.Width; 
     if (newHeight > height) 
     { 
      width = image.Width * height/image.Height; 
      newHeight = height; 
     } 
     Image NewImage = image.GetThumbnailImage(width, newHeight, null, IntPtr.Zero); 
     return NewImage; 
    } 
} 

我希望這有助於。

相關問題