/// <summary> /// 截取圖片區域,返回所截取的圖片 /// </summary> /// <param name="SrcImage"></param> /// <param name="pos"></param> /// <param name="cutWidth"></param> /// <param name="cutHeight"></param> /// <returns></returns> private Image cutImage(Image SrcImage, Point pos, int cutWidth, int cutHeight) { Image cutedImage = null; //先初始化一個位圖對象,來存儲截取后的圖像 Bitmap bmpDest = new Bitmap(cutWidth, cutHeight, PixelFormat.Format32bppRgb); Graphics g = Graphics.FromImage(bmpDest); //矩形定義,將要在被截取的圖像上要截取的圖像區域的左頂點位置和截取的大小 Rectangle rectSource = new Rectangle(pos.X, pos.Y, cutWidth, cutHeight); //矩形定義,將要把 截取的圖像區域 繪制到初始化的位圖的位置和大小 //rectDest說明,將把截取的區域,從位圖左頂點開始繪制,繪制截取的區域原來大小 Rectangle rectDest = new Rectangle(0, 0, cutWidth, cutHeight); //第一個參數就是加載你要截取的圖像對象,第二個和第三個參數及如上所說定義截取和繪制圖像過程中的相關屬性,第四個屬性定義了屬性值所使用的度量單位 g.DrawImage(SrcImage, rectDest, rectSource, GraphicsUnit.Pixel); //在GUI上顯示被截取的圖像 cutedImage = (Image)bmpDest; g.Dispose(); return cutedImage; }