2017/12/13

【C#】簡易圖片編輯

命名空間

using System.Drawing;

繪圖介面
Graphics graphicInterface;

圖片物件
Image sourceImage;

開啟舊檔
sourceImage = Image.FromFile( 路徑字串 , false );

以Bitmap格式開新檔案並轉為Image
sourceImage =  new Bitmap(寬, 高) as Image;

釋放資源(關閉檔案)
sourceImage.Dispose();

以image為畫布進行操作
graphicInterface = Graphics.FromImage(outputImage);

將整張畫布填滿白色
graphicInterface.Clear(Color.White);

另存新檔
sourceImage.Save(完整路徑及檔名 , 檔案格式);
檔案格式種類
System.Drawing.Imaging.ImageFormat.Jpeg
也可以指定其他如Bmp、Git、Icon、Jpeg、Png等等

沒有留言: