请大家来看看我的这段制作缩略图代码是哪错了~~~

turan 2004-07-17 01:30:27
这段代码是我从网上的一段程序里面分离出来的。当我运行整个程序的时候很正常,但是一旦运行这些代码,错误就出在
image=System.Drawing.Image.FromFile(Server.MapPath("photolib\")&filename)
这一句上面。本人对Asp.net了解不深,大家帮我看看为什么会这样?

其中,变量filename是从上一个页面的Session中取的值。
在这里先谢谢各位啦~~


<script language="VB" runat="server">

Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort

image=System.Drawing.Image.FromFile(Server.MapPath("photolib\")&filename)
width=image.Width
height=image.height
if width>height then
newwidth=120
newheight=image.height/image.Width*newwidth
else
newheight=120
newwidth=image.Width/image.height*newheight
end if

aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
aNewImage.Save(Server.MapPath("photo_s\")&filename)
image.Dispose()

</script>
...全文
177 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
win911 2004-07-17
  • 打赏
  • 举报
回复
圖片保存的位置和讀取的位置要一致,檢查是否含有photolib這個目錄
孟子E章 2004-07-17
  • 打赏
  • 举报
回复
看看
Server.MapPath("photolib\")&filename
路径是否是对的

http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538
devfan 2004-07-17
  • 打赏
  • 举报
回复
public class ShowSmallImage : System.Web.UI.Page
{
const int MaxLength=150; //最大长度

private void Page_Load(object sender, System.EventArgs e)
{
if (Request.QueryString["filename"] != null)
{
//取得原图
string filename=Request.QueryString["filename"];
Bitmap bmpOld= new Bitmap(Server.MapPath("images/" + filename));

//计算缩小比例
double d1;
if (bmpOld.Height>bmpOld.Width)
d1=(double)(MaxLength/(double)bmpOld.Width);
else
d1=(double)(MaxLength/(double)bmpOld.Height);

//产生缩图
Bitmap bmpThumb= new Bitmap(bmpOld,(int)(bmpOld.Width*d1),(int)(bmpOld.Height*d1));

// 清除缓冲
Response.Clear();
//生成图片
bmpThumb.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
//释放资源
bmpThumb.Dispose();
bmpOld.Dispose();
}
}

}
turan 2004-07-17
  • 打赏
  • 举报
回复
呵呵,谢谢楼上。刚才我也找到了解决方法。

For those of you who are working with VB.NET and ASP.NET, you may have experienced a problem where when you try to load an ASP.NET page, you get the following error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.

This error is due to the way ASP.NET handles inline code differently from ASP.OLD. In the original ASP, there was hardly any difference between using <script runat="server"></script> and <% %> to block off your server side code. In ASP.NET, there is a huge difference.

When you use the <script runat="server"></script> tags to define a block of code, essentially ASP.NET inlines everything between the blocks directly into the body of the class that is generated for the page. In other words, you can define variables for the class, and routines or functions for a class, but you cannot directly include source code inside a <script> tag.

However, if you use the <% %> tags to isolate your code blocks, ASP.NET essentially creates a new function that is executed at that point in the document cycle. All of the inner text of this block is dumped into the internals of the function, which means that you can use source code or definitions or whatever else you want inside of this tag, and you won't get an error. I say that it essentially creates a function because it doesn't really, variables that are defined inside a <% %> block are scoped for the entire page, so that any code running in the page can access them. This is different than if you were creating real functions.

Unfortunately the error message given when you run into this problem is very unclear, and really gives you no good sense of what is occuring and what the problem might be. I hope this makes this a little clearer, and helps solve some of the confusion original ASP developers might have when moving to ASP.NET.

文章大意就是楼上所说的了。
saucer 2004-07-17
  • 打赏
  • 举报
回复
ASP.NET与ASP不同,你需要把执行语句放在方法里

<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e as EventArgs)

Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort

image=System.Drawing.Image.FromFile(Server.MapPath("photolib\")&filename)
width=image.Width
height=image.height
if width>height then
newwidth=120
newheight=image.height/image.Width*newwidth
else
newheight=120
newwidth=image.Width/image.height*newheight
end if

aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
aNewImage.Save(Server.MapPath("photo_s\")&filename)
image.Dispose()

End Sub
</script>
turan 2004-07-17
  • 打赏
  • 举报
回复
我用这段程序,是用来把变量中的文件生成器缩略图。

运行的时候错误代码如下:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 15: Dim callb As System.Drawing.Image.GetThumbnailImageAbort
Line 16:
Line 17: image=System.Drawing.Image.FromFile(Server.MapPath("photolib\")&filename)
Line 18: width=image.Width
Line 19: height=image.height
SeeSunSet 2004-07-17
  • 打赏
  • 举报
回复
<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
void UploadBtn_Click(Object sender, EventArgs e) {
String filename;
String filename1;
String[] filename2;
int q;
filename=UploadFile.PostedFile.FileName ;
filename2=filename.Split(new Char[] {'\\'});
q=filename2.GetUpperBound(0);
filename1=filename2[q];
dis.Text="上传文件名:"+filename1+"<br/>";
UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
ImageEditor.Visible = true;
dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
Image1.Src=filename1;
}
void UpdateBtn_Click(Object sender, EventArgs e) {
String filename1;
filename1=Image1.Src;
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
Graphics g = Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
Brush b = new SolidBrush(Color.Red);
g.DrawString(Caption.Text, f, b, 10, 140);
g.Dispose();
System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse(Height.Text),null,0);
image.Dispose();
thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG);
Image1.Src=filename1;
Caption.Text="";

}

</script>

<body>
<asp:label id="dis" runat=server/>
<form enctype="multipart/form-data" runat=server>

<h3>

Select File To Upload: <input id="UploadFile" type=file runat=server>

<asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/>

<hr>

<asp:panel id="ImageEditor" Visible=false runat=server>

<img ID="Image1" src="" runat="server"/>

<h3>
Image Width: <asp:textbox id="Width" runat=server/>

Image Height: <asp:textbox id="Height" runat=server/> <br/>

Text Caption: <asp:textbox id="Caption" runat=server/>

Caption Size: <asp:dropdownlist id="FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
Caption Font: <asp:dropdownlist id="FontType" runat=server>
<asp:listitem>黑体</asp:listitem>
<asp:listitem>仿宋</asp:listitem>
<asp:listitem>隶书</asp:listitem>
<asp:listitem>楷书</asp:listitem>
<asp:listitem>方正姚体</asp:listitem>
<asp:listitem>华文彩云</asp:listitem>
</asp:dropdownlist>

<asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/>

</h3>
</asp:panel>

</form>

</body>
</html>



直接用吧.不会错的.
saucer 2004-07-17
  • 打赏
  • 举报
回复
what error message? try to move the code inside a method
46539492 2004-07-17
  • 打赏
  • 举报
回复
image=System.Drawing.Image.FromFile(Server.MapPath("photolib\")&filename)
--------------------
image=System.Drawing.Image.FromFile(Server.MapPath("photolib\" & filename))

62,243

社区成员

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

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

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

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