一、图片裁剪插件
演示Demo:http://www.htmleaf.com/Demo/201608063831.html
下载网址:http://www.htmleaf.com/jQuery/Image-Effects/201608063830.html
二、 实现C#把裁剪的图片保存在本地
把前端的X坐标、Y坐标、裁剪的宽度、裁剪的高度传入后即可
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 图片裁剪 { class Program { static void Main(string[] args) { } #region 从大图中截取一部分图片 /// <summary> /// 从大图中截取一部分图片 /// </summary> /// <param name="fromImagePath">来源图片地址</param> /// <param name="offsetX">从偏移X坐标位置开始截取</param> /// <param name="offsetY">从偏移Y坐标位置开始截取</param> /// <param name="toImagePath">保存图片地址</param> /// <param name="width">保存图片的宽度</param> /// <param name="height">保存图片的高度</param> /// <returns></returns> public static void CaptureImage(string fromImagePath, int offsetX, int offsetY, string toImagePath, int width, int height) { //原图片文件 Image fromImage = Image.FromFile(fromImagePath);
//原图位图
Bitmap bmp = new Bitmap(fromImage); //创建新图位图 Bitmap bitmap = new Bitmap(width, height); //创建作图区域 Graphics graphic = Graphics.FromImage(bitmap); //截取原图相应区域写入作图区 graphic.DrawImage(fromImage, 0, 0, new Rectangle(offsetX, offsetY, width, height), GraphicsUnit.Pixel); //从作图区生成新图 Image saveImage = Image.FromHbitmap(bitmap.GetHbitmap()); //保存图片 saveImage.Save(toImagePath, ImageFormat.Png); //释放资源
saveImage.Dispose(); saveImage.Dispose(); graphic.Dispose(); bitmap.Dispose(); } #endregion } }
删除文件
public static void DeleteFile(string fileUrl) { string file = System.Web.HttpContext.Current.Server.MapPath(fileUrl); if (System.IO.File.Exists(file)) { System.IO.File.Delete(file); } }
后续会陆续更新其他资料,喜欢请关注哦!