using System.Drawing;
static void Main(string[] args) { // 讀取圖片到bitmap,需自行設定路徑 Bitmap originalImage = new Bitmap("original.jpg"); // 設定長寬,就算原尺寸容量也會差很多喔 int newWidth = 300; int newHeight = (int)(originalImage.Height * ((float)newWidth / originalImage.Width)); //新增一個bipmap暫存 Bitmap resizedImage = new Bitmap(newWidth, newHeight); //寫入暫存圖檔 using (Graphics g = Graphics.FromImage(resizedImage)) { g.DrawImage(originalImage, 0, 0, newWidth, newHeight); } //儲存 resizedImage.Save("resized.jpg", ImageFormat.Jpeg); }
沒有留言:
張貼留言