=波波日志 > Asp.Net/C#/WCF > GDI+ 中发生一般性错误=
GDI+ 中发生一般性错误
在使用System.Drawing.Bitmap.Save保存图片时,图片路径需要为物理路径,要不就会出现“GDI+ 中发生一般性错误”的错误提示,Save方法不接收虚拟路径,参数为物理路径,要使用Server.MapPath将虚拟路径转换成物理路径。
下面是一个在csdn上看到的图片采集功能功能,由于使用了虚拟路径,所以出现了GDI+ 中发生一般性错误的问题,转换为物理路径后就可以了。
当然出现个问题可能为权限问题,目录不存在等的问题。
下面为CSDN源代码
下面是一个在csdn上看到的图片采集功能功能,由于使用了虚拟路径,所以出现了GDI+ 中发生一般性错误的问题,转换为物理路径后就可以了。
当然出现个问题可能为权限问题,目录不存在等的问题。
下面为CSDN源代码
+展开
-C#
using System;
using System.IO;
using System.Net;
using System.Drawing;
public partial class img : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bigimg = "http://i2.3conline.com/images/pcautogallery/20099/20/st/9717/80_bthumb.JPG";
int pPartWidth, pPartHeight, pPartStartPointX, pPartStartPointY, pOrigStartPointX, pOrigStartPointY;
string normalJpgPath = Server.MapPath("/SiteImg/" + DateTime.Now.ToString("hhmmssff") + ".jpg");
//下面的没转成物理路径,所以出错
//string normalJpgPath ="/SiteImg/" + DateTime.Now.ToString("hhmmssff") + ".jpg";
pPartStartPointX = 0;
pPartStartPointY = 0;
pOrigStartPointX = 0;
pOrigStartPointY = 0;
WebClient client = new System.Net.WebClient();
Stream stm = client.OpenRead(bigimg);
Image originalImg = Image.FromStream(stm, true);
pPartWidth = originalImg.Width;
pPartHeight = originalImg.Height;
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight);
Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));
graphics.DrawImage(originalImg, destRect, origRect, GraphicsUnit.Pixel);
graphics.DrawImage(originalImg, 0, 0);
stm.Close();
originalImg.Dispose();
if (File.Exists(normalJpgPath))
{
File.SetAttributes(normalJpgPath, FileAttributes.Normal);
File.Delete(normalJpgPath);
}
partImg.Save(normalJpgPath, System.Drawing.Imaging.ImageFormat.Jpeg);
partImg.Dispose();
}
}
using System.IO;
using System.Net;
using System.Drawing;
public partial class img : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bigimg = "http://i2.3conline.com/images/pcautogallery/20099/20/st/9717/80_bthumb.JPG";
int pPartWidth, pPartHeight, pPartStartPointX, pPartStartPointY, pOrigStartPointX, pOrigStartPointY;
string normalJpgPath = Server.MapPath("/SiteImg/" + DateTime.Now.ToString("hhmmssff") + ".jpg");
//下面的没转成物理路径,所以出错
//string normalJpgPath ="/SiteImg/" + DateTime.Now.ToString("hhmmssff") + ".jpg";
pPartStartPointX = 0;
pPartStartPointY = 0;
pOrigStartPointX = 0;
pOrigStartPointY = 0;
WebClient client = new System.Net.WebClient();
Stream stm = client.OpenRead(bigimg);
Image originalImg = Image.FromStream(stm, true);
pPartWidth = originalImg.Width;
pPartHeight = originalImg.Height;
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight);
Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));
graphics.DrawImage(originalImg, destRect, origRect, GraphicsUnit.Pixel);
graphics.DrawImage(originalImg, 0, 0);
stm.Close();
originalImg.Dispose();
if (File.Exists(normalJpgPath))
{
File.SetAttributes(normalJpgPath, FileAttributes.Normal);
File.Delete(normalJpgPath);
}
partImg.Save(normalJpgPath, System.Drawing.Imaging.ImageFormat.Jpeg);
partImg.Dispose();
}
}
类别:Asp.Net/C#/WCF 作者:波波 日期:2010-07-09 【评论:0】
暂时没有评论!
发表留言
百度赞助
同类热门博文
- ·IE里Cookie跨域不能..
- ·去掉隐藏asp.net编译..
- ·解决asp.net验证视图..
- ·找不到System.Web.S..
- ·web服务因URL意外地..
- ·C#2.0中,SerialPor..
- ·用C#编写ActiveX控件..
- ·用C#编写ActiveX控件..
博格Tag
- flash/flex/fcs/AIR(752)
- Asp.Net/C#/WCF(598)
- 操作系统及应用软件(376)
- JavaScript/Ajax(330)
- SQL及数据库(134)
- 黑客技术(115)
- Asp/VBScript(111)
- HTML/WML/CSS兼容/XML(102)
- PHP/apache/Perl(96)
- 网站排名及优化(96)
- 其他(75)
- showbo日志(66)
- lucene.net/分词技术(33)
- 计算机网络(26)
- 机械重工(26)
- C#设计模式(25)
- Google Maps开发(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(11)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
- ·详解SqlConnection连..
- ·C#实现的html内容截..
- ·asp.net web.config..
- ·asp.net<%--注释--%..
- ·ASP.NET环境配置常见..
- ·asp.net防止图片盗链..
- ·Session.Abandon的使..
- ·asp中缓存cache技术..
随机博文
