• 分享一个JQuery 图片裁剪插件,然后用C# 把裁剪的图片保存在本地


    一、图片裁剪插件

      演示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);
                }
            }

      后续会陆续更新其他资料,喜欢请关注哦!

      我的博客:https://www.cnblogs.com/duhaoran/

  • 相关阅读:
    自定义的弹出框列表适配器,类似于大众点评或美团
    Android 微信支付&支付宝支付
    动态设置 view 在布局中位置
    android 之图片异步加载
    android 侧滑菜单
    Google 官方 侧滑 drawerlayout
    python D27网络传输协议
    计算机单位换算、以及sort、sorted函数的区别
    python D26 socket、网络整个通信流程
    python D25 包
  • 原文地址:https://www.cnblogs.com/duhaoran/p/13634170.html
Copyright © 2020-2023  润新知