/**//// <summary>
/// http://www.cnblogs.com/KissKnife/archive/2007/10/13/923352.Html
/// 獲取圖片指定部分
/// </summary>
/// <param name="pPath">圖片路徑</param>
/// <param name="pPartStartPointX">目標圖片開始繪制處的坐標X值(通常為0)</param>
/// <param name="pPartStartPointY">目標圖片開始繪制處的坐標Y值(通常為0)</param>
/// <param name="pPartWidth">目標圖片的寬度</param>
/// <param name="pPartHeight">目標圖片的高度</param>
/// <param name="pOrigStartPointX">原始圖片開始截取處的坐標X值</param>
/// <param name="pOrigStartPointY">原始圖片開始截取處的坐標Y值</param>
static System.Drawing.Bitmap GetPart(string pPath, int pPartStartPointX, int pPartStartPointY, int pPartWidth, int pPartHeight, int pOrigStartPointX, int pOrigStartPointY)
...{
System.Drawing.Image originalImg = System.Drawing.Image.FromFile(pPath);
System.Drawing.Bitmap partImg = new System.Drawing.Bitmap(pPartWidth, pPartHeight);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(partImg);
System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(new System.Drawing.Point(pPartStartPointX, pPartStartPointY), new System.Drawing.Size(pPartWidth, pPartHeight));//目標位置
System.Drawing.Rectangle origRect = new System.Drawing.Rectangle(new System.Drawing.Point(pOrigStartPointX, pOrigStartPointY), new System.Drawing.Size(pPartWidth, pPartHeight));//原圖位置(默認從原圖中截取的圖片大小等於目標圖片的大小)
graphics.DrawImage(originalImg, destRect, origRect, System.Drawing.GraphicsUnit.Pixel);
return partImg;
}
此文件寫在類中,也可以寫在窗體事件中.
文中鏈接地址是搜索到的,修改了原文中保存的參數
歡迎光臨學網,收藏本篇文章