图像保存时遇到问题!

quou2002 2004-08-03 08:17:37
System.Drawing.Image img=System.Drawing.Image.FromFile(Server.MapPath("test.gif"));
img.Save(Server.MapPath("test2.gif"));

-------catch捕获的错误:
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at test.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform2.aspx.cs:line 61
-------
这是什么原因?我先以为权限不够,可将iis里的虚拟目录的“写入”勾上还是不行。
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
暗石绿 2004-08-05
  • 打赏
  • 举报
回复
-------catch捕获的错误:
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at test.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform2.aspx.cs:line 61
-------
这是什么原因?我先以为权限不够,可将iis里的虚拟目录的“写入”勾上还是不行。


*********************************************************************************

确实是权限不够的原因。
我估计你 iis 的虚拟目录指向的文件夹是在 NTFS 格式的硬盘上的。
如 iis 的虚拟目录指向的文件夹名为 LocalHost

应该是右击 LocalHost ,在“共亨与安全”属性里选中“安全”选项卡,添加 aspnet 用户,给 aspnet 用户添加全权。
quou2002 2004-08-04
  • 打赏
  • 举报
回复
nnh(菲一打),首先,你那一行:
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
有误,应该是:
dim strFileFolder as string =Server.MapPath("../uploadfile_ok/1/")

其次,我问的是Image的Save方法为什么这里会出错。还是不解阿!!!
nnh 2004-08-04
  • 打赏
  • 举报
回复
<%@ Import Namespace="System.IO" %>
<%@ page Language="vb" debug="true" codepage="936"%>
<html><head><title>UpLoadFile_VB.aspx</title>
<script language="vb" runat="server">
Sub UploadFile(sender as object ,E as EventArgs)
if not myFile.PostedFile is Nothing then
dim PicSize as string=myFile.PostedFile.ContentLength.ToString()

dim strFileName as string =myFile.PostedFile.FileName.ToString()


dim namei as integer =strFileName.LastIndexOf(".")
dim strNameX as string=strFileName.Substring(namei)
'Set another file name
dim strNewName as string =Request.UserHostAddress.ToString()+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+strNameX

dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
dim strNewFilePath as string =strFileFolder+strNewName

myFile.PostedFile.SaveAs(strNewFilePath)

name.Text=strFileName
fname.Text=myFile.PostedFile.FileName
fenc.Text=myFile.PostedFile.ContentType
fsize.Text=myFile.PostedFile.ContentLength.ToString()
name_cc.Text=strNameX
filesaveto.Text=strNewFilePath
newfilename.Text=strNewName
end if
End Sub
</script>
</head>
<body>
<center>
<h3> UpLoad Files By VB_NET_5 </h3>
<form id="uploderform" method="post" action="uploadfile_c_5.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="0" cellpadding="0" >
<tr> <td><h5>Select File</h5></td</tr>
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="0" width="500">
<tr>
<td width="200">Filename:</td>
<td><asp:label id="name" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="name_cc" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fname" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="filesaveto" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fenc" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fsize" runat="server" />
<tr>
<td></td>
<td><asp:label id="newfilename" runat="server" />
</td></tr>
</td></tr>
</table>
</center>
</body>
</html>
quou2002 2004-08-04
  • 打赏
  • 举报
回复
请问你们通常是如何保存图片的?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧