问题场景:asp.net给图片添加文字水印保存为jpg格式时出现标题所描述错误(图片为.jpg格式);

简单验证:用本机的画图程序打开,然后保存为jpg格式会出现警告框“画图程序不能存储该文件,保存被中断  所以文件未被保存“

 

 

解决代码:

             try
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromFile(@"D:\WWW\test\DownLoad\企业毕业证书.jpg"))
                {

                    #region 解决方案一,移除属性,可以保存为jpeg格式图片
                    System.Drawing.Imaging.PropertyItem[] pi = image.PropertyItems;
                    foreach (System.Drawing.Imaging.PropertyItem p in pi)
                    {
                        image.RemovePropertyItem(p.Id);
                    }

                    #endregion

                    Response.Write("1" + "\r\n");
                    //新建一个画板
                    System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
                    Response.Write("2" + "\r\n");
                    graphic.DrawImage(image, 0, 0, image.Width, image.Height);
                    Response.Write("3" + "\r\n");

                    //设置字体
                    System.Drawing.Font f = new System.Drawing.Font("宋体", 12);
                    Response.Write("4" + "\r\n");

                    //设置字体颜色
                    System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                    Response.Write("5" + "\r\n");
                    graphic.DrawString("2", f, b, 729, 326);
                    Response.Write("6" + "\r\n");
                    graphic.DrawString("2013", f, b, 1083, 1325);
                    graphic.DrawString("12", f, b, 1375, 1325);
                    graphic.DrawString("2", f, b, 1842, 1325);
                    graphic.DrawString("99", f, b, 2676, 1325);
                    graphic.DrawString("13", f, b, 656, 326);
                    graphic.DrawString("12", f, b, 1083, 1485);
                    graphic.DrawString("12", f, b, 1375, 1485);
                    graphic.DrawString("1", f, b, 1928, 1485);
                    graphic.DrawString("1", f, b, 2735, 1485);
                    graphic.DrawString("2013", f, b, 2494, 1837);
                    graphic.DrawString("12", f, b, 2673, 1837);
                    graphic.DrawString("31", f, b, 2790, 1837);
                    Response.Write("7" + "\r\n");
                    //设置字体
                    System.Drawing.Font f1 = new System.Drawing.Font("宋体", 18);
                    Response.Write("8" + "\r\n");
                    graphic.DrawString("2", f1, b, 1412, 988);
                    graphic.DrawString("test", f1, b, 1471, 1132);
                    Response.Write("9" + "\r\n");
                    graphic.Dispose();
                    Response.Write("10" + "\r\n");

                    string OutPath = Server.MapPath("UploadImg/毕业证书");
                    if (!Directory.Exists(OutPath))
                    {
                        Response.Write("11" + "\r\n");
                        Directory.CreateDirectory(OutPath);
                    }
                    Response.Write("12" + "\r\n");
                    string Savepath = Path.Combine(@"D:\WWW\test\UploadImg\毕业证书", "1.JPG");

                    System.Drawing.Image outimg = image;

                    Response.Write("13" + "\r\n");
                    outimg.Save(Savepath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    #region 解决方案二,保存为png格式图片

                    outimg.Save(Savepath,System.Drawing.Imaging.ImageFormat.Png);

                    #endregion
                    outimg.Dispose();
                    Response.Write("14" + "\r\n");
                    Response.Write("15" + "\r\n");

                    Response.Write(Savepath);

                }
            }
            catch (Exception ex)
            {

                Response.Write(ex.Message);
            }

System.Drawing.Image.Save(Savepath),保存为jpg格式,参数错误,文件0kb解决办法的更多相关文章

  1. asp.net EF6.0中出现未找到具有固定名称“System.Data.SqlClient”的 ADO.NET提供程序的实体框架提供程序解决办法

    出现的错误信息如下所示: 指定的架构无效.错误:  DataModel.ssdl(2,2) : 错误 0152: 未找到具有固定名称“System.Data.SqlClient”的 ADO.NET 提 ...

  2. Activiti保存流程图时diagrms中没有生成png解决办法

    window ——> preferences——>activiti——>save——>选中create process definition image when saving ...

  3. EF6.0中出现未找到具有固定名称“System.Data.SqlClient”的 ADO.NET提供程序的实体框架提供程序解决办法

    在多工程项目中,由于EF封装在某一个工程里,那么该项目用于EF相关类库 EntityFramework.dll,以及EntityFramework.SqlServer.dll的引用 那么你一个启动工程 ...

  4. 使用System.Drawing.Imaging.dll进行图片的合并

    在最近开发项目的时候有时候需要进行图片的合并,即将两张图片合并成功一张图片 合并图片的代码: #region 两张图片的合并 /// <summary > /// 将Image对象转化成二 ...

  5. 类库探源——System.Drawing

    一.System.Drawing 命名空间简述 System.Drawing 命名空间提供访问 GDI+ 的基本功能,更高级的功能在 System.Drawing.Drawing2D,System.D ...

  6. [Tomcat]无法使用tomcat6.exe启动服务解决办法, The system cannot find the Registry key for service 'tomcat7'

    重新配置环境变量后,可以使用startup.bat启动服务, 但是无法使用tomcat6.exe启动服务, 错误信息: [2011-03-10 18:51:49] [warn]  The system ...

  7. .net学习笔记----利用System.Drawing.Image类进行图片相关操作

    C#中对图片的操作主要是通过System.Drawing.Image等类进行. 一.将图片转换为字节流 /// <summary> /// 图片处理帮助类 /// </summary ...

  8. Asp.Net Core使用System.Drawing.Common部署到docker报错问题

    Asp.Net Core 2.1发布后,正式支持System.Drawing.Common绘图了,可以用来做一些图片验证码之类的功能.但是把网站部署到docker容器里运行会遇到很多问题,也是非常闹心 ...

  9. 把System.Drawing.Image对象img,在页面的Image控件上显示出来

    1.保存到本地,然后调用. //定义文件名    string iname = DateTime.Now.ToString("yyMMddhhmmss"); //保存到服务器,b是 ...

随机推荐

  1. SQL报错error:索引中丢失IN或OUT參数

    简单记录下: 今天mybatis中遇到一个错误: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallba ...

  2. VSS Get Latest Version 没有提示recursive的对话框解决

    今天按照VSS使用时,当“Get Latest version”时,不小心勾选了 “Only show this dialog when the Shift key is down”,因此当我再“Ge ...

  3. [转] Transitions: Going from Shots to the Insulin Pump

    Part three of our article series on the common phases of type 2 diabetes management By Lance Porter ...

  4. [转] 深入剖析 linux GCC 4.4 的 STL string

    本文通过研究STL源码来剖析C++中标准模板块库std::string运行机理,重点研究了其中的引用计数和Copy-On-Write技术. 平台:x86_64-redhat-linux gcc ver ...

  5. .Net写txt文件-简单的记录执行日志信息代码

    在执行一些批量操作时,想记录一些执行日志信息,越简单方便越好啊.提供一个常用的简单方法,将信息记录在txt文件里: public static void log(string content, str ...

  6. Android Studio 安装

    准备: JDK 7以及以上版本. Android Studio安装文件  中文站下载 http://www.android-studio.org/index.php/download exe ,包含S ...

  7. .Net使用SSH.NET通过SSH访问Linux主机

    使用了SSH.NET库,添加引用dll至项目,以下代码显示了点击按钮后SSH链接Linux主机执行命令并返回命令执行结果 protected void btnExcute_Click(object s ...

  8. maven中pom.xml

    1. GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构. ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称.一般 ...

  9. iOS中解析 XML / JSON

    JSON数据格式 1. 概述: JSON (JavaScript Object Notation) 是⼀一种轻量级的数据交换格式 基于⽂文本格式,易于⼈人阅读和编写,同时也易于机器解析和⽣生成. 2. ...

  10. Oracle数据库之创建表结构

    Oracle数据库之创建表结构 主键与外键 主键:关系型数据库中的一条记录中有若干个属性,若其中的某一个属性组(可以是一个属性,也可以是多个)能唯一标识一条记录,那么该属性组就是主键. 外键:关系型数 ...