生活随笔
收集整理的這篇文章主要介紹了
c# 从一个大图里截取图形
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
public?void?DrawImage( ????Image?image, ????Rectangle?destRect, ????Rectangle?srcRect, ????GraphicsUnit?srcUnit ) public?void?DrawImage( ????Image?image, ????int?x, ????int?y, ????Rectangle?srcRect, ????GraphicsUnit?srcUnit )
[c-sharp]?view plain
copy #region???截取圖象?? ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?public?static?void?CaptureImage(string?sFromFilePath,?string?saveFilePath,?int?width,?int?height,?int?spaceX,?int?spaceY)?? ?{?? ??????? ?????Image?fromImage?=?Image.FromFile(sFromFilePath);?? ?????int?x?=?0;????? ?????int?y?=?0;????? ??????? ??????? ??????? ??????? ?????int?sX?=?fromImage.Width?-?width;?? ?????int?sY?=?fromImage.Height?-?height;?? ?????if?(sX?>?0)?? ?????{?? ?????????x?=?sX?>?spaceX???spaceX?:?sX;?? ?????}?? ?????else?? ?????{?? ?????????width?=?fromImage.Width;?? ?????}?? ?????if?(sY?>?0)?? ?????{?? ?????????y?=?sY?>?spaceY???spaceY?:?sY;?? ?????}?? ?????else?? ?????{?? ?????????height?=?fromImage.Height;?? ?????}?? ?? ??????? ?????Bitmap?bitmap?=?new?Bitmap(width,?height);?? ??????? ?????Graphics?graphic?=?Graphics.FromImage(bitmap);?? ??????? ?????graphic.DrawImage(fromImage,?0,?0,?new?Rectangle(x,?y,?width,?height),?GraphicsUnit.Pixel);?? ??????? ?????Image?saveImage?=?Image.FromHbitmap(bitmap.GetHbitmap());?? ??????? ?????saveImage.Save(saveFilePath,?ImageFormat.Jpeg);?? ??????? ?????saveImage.Dispose();?? ?????bitmap.Dispose();?? ?????graphic.Dispose();?? ?}?? ?#endregion?? ?
//調(diào)用方法
???????? CaptureImage(@"D:/1.jpg", @"d:/2.jpg", 50, 50, 300, 300);
總結(jié)
以上是生活随笔為你收集整理的c# 从一个大图里截取图形的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。