ASP.NET很容易的图片裁剪功能
public class PicCut
{
/// <summary>
///
/// </summary>
/// <param name="AbsoluteFileName">虚拟</param>
/// <param name="SaveServer">图片虚拟路径</param>
/// <param name="x">裁剪横坐标</param>
/// <param name="y">裁剪的纵坐标</param>
/// <param name="CutHeight">裁剪高度</param>
/// <param name="CutWeight">裁剪宽度</param>
/// <returns></returns>
public static bool NewCutPic(string AbsoluteFileName, string SaveServer, int x, int y, int CutHeight, int CutWeight)
{
bool Result = false;
using (Image img = Image.FromFile(AbsoluteFileName))
{
int OriginalWidth = img.Width;
int OrginalHeight = img.Height;
using (Bitmap bm = new Bitmap(CutWeight, CutHeight))
{
Graphics grap = Graphics.FromImage(bm);
//grap.Clear(Color.Transparent);
//grap.Clear(Color.White);
Color BgColor = Color.FromArgb(235, 235, 235);
grap.Clear(BgColor);
Rectangle rt = new Rectangle(0, 0, CutWeight, CutHeight); //从截取位置获取
Rectangle ort = new Rectangle(new Point(x, y), new Size(CutWeight, CutHeight)); //图片截取大小
grap.DrawImage(img, rt, ort, GraphicsUnit.Pixel);
string MapPath = HttpContext.Current.Server.MapPath(SaveServer);
//[AbsoluteFileName原存放在服务器的图片路径]删除后将减少服务器存放容量]
bm.Save(MapPath, ImageFormat.Jpeg);
grap.Dispose();
}
}
return Result;
}
}
qq讨论群 : 171560784