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

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>
...全文
175 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))
persistent_layers 不管滚动条如何拉动,这个层在窗口中的位置始终固定不变 P7_PowerToys_18 可以让你方便的插入代码,用开始和结束标签加入既存的代码等 justsoalt 用于在你的图片上加入alt标记,它可以利用模板一次为多张图片加入alt说明 calendarPopup 一个弹出日历表格,用以确保输入的日历是按照特定的格式进行输入的,主要特色包括:日历链接,按照需要的方式设定日历的格式,按照需要可以在日期项目间增加分隔符等等功能 MX95982_shortcutIconOB_v1 插入.icon图标效果 addToFavoritesBH 制作加入收藏夹的链接 Anchors 建立扩展的命令锚点 BustFrames 让其他网页无法将你的主页加载入框架页中 Calendar 为指定月份建立日历 ClosePopupWindow 制作关闭弹出的窗口 CloseWindowOb 建立关闭当前窗口的链接 mm_flabutton_styles 为DW4增加几款新的Flash按钮样式 mx142100_mmflabuttonstyles 13款Flash Button,并带有.fla的源文件 mx196756_turkeyscounties 80多个国家的一个下拉菜单 FlashImage 响应鼠标事件的图片渐显渐隐效果 real_networks 在页面中插入流式播放的Real视频和音频文件 MX131662_pdreloadxtension 从新加载Dreamweaver的各项插件,不用重复的启动关闭Dreamweaver了 DateStamp 插入一个日期,或者网页的最后更新日期 Email 插入一个Email的连接,可以自己指定标题、BB、BBC、以及message! ie55_scroll 自定义浏览器滚动条的特效CSS Marquee 插入滚动文字效果 scrubber 去除点击超级链接时的虚线显示 chromeless_win_wind 制作弹出无边浏览小窗口,现在网上最为流行的 scrollablearea 使用层制作IE中可控制上下滚动的看板 right_click_menu_builder 右键菜单扩展功能 flashtext 制作仿Flash的文字效果 typewriter 让一段文字以打字的效果出现 gradient_text 在网页里生成一段色彩渐变的文字 footnote 增加一个弹出的注释,就像image 的alt=…… ie_favicon 你只需要一个漂亮的ico格式图片,您的地址栏IE图标将与众不同 favorite_menu 为DW增加一个Favorites 菜单,类似IE收藏夹 layer_transitions 层的多种转换特效 dhtml_tooltips 为页面或链接增加一个dHTML的脚注(即注释) insert_greeting 根据不同的时段插入不同的问候语 script_editor 让你更方便的编辑脚本,包括外部脚本 popup_menu_builder 帮助您轻松创建一个跨浏览器的弹出菜单 TableLines 文章文字各行间都有横线分离 alternate_table_rows 使表格中行与行之间的背景色交替变换 print 支持三种打印页面连接,文字连接、图片连接 preloaddisplay 预先加载页面,如果你的网站下载的速度比较慢,用这个比较好。 swftext 将Drm和Flash结合起来了,选择文本,执行该Command,swf动画就轻易的生成了 SliderMenu 设计导航菜单的绝佳助手,可以用于导航菜单的设计,特别是导航项很多的场合 disable_view_source 让网页源代码无法观看 vmkp_flash_buttons Flash按钮 iframe 内帖窗口(页中页效果) open_picture_window 打开一个与缩略图一样大小的窗口 MX128577_ultimatewindows 建立一个可自定义属性的弹出窗口,亦可建立一个居中的窗口 WordCount 字数统计 PreviousPage 建立返回前一页的超链接 PageTransitions 进入、退出页面的过渡转场效果,比如从中间打开、溶解...... Meta_Generator 网页 Meta 管理器,可以详细设置Meta Fix_Null_Links 把所有的“#”替换成“javascript”来避免一点击它,网页马上就翻到了顶部 advopenwindow 弹出窗口(窗口居中、总在最前面、自动关闭、全屏、无边框窗口) averagedistribute 单元格平均分布 Quick_Title 建立文字型的Title说明 Open_Brows

62,244

社区成员

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

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

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

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