ASP+上载例子
花君
下面是用ASP+来纺写的上载例子!!在ASP中我们就才上载有许多组件:
<html>
<script language="VB" runat=server>
'VB代码
Sub UploadBtn_Click(Sender as Object, E as EventArgs)
'以上载为例
UploadFile.PostedFile.SaveAs(Server.MapPath("http://www.aspcool.com/lanmu/test.jpg"))
MyImage.ImageUrl = "http://www.aspcool.com/lanmu/test.jpg"
MyImage.Visible = true
End Sub
</script>
<body>
<form enctype="multipart/form-data" runat=server>
<h3>
选择要上载的文件:
<input type=file runat=server>
<asp:button text="Upload Me!" runat=server/>
<hr>
<asp:image visible=false runat=server/>
</form>
</body>
</html>
下面是一个更详细的例子,其可以上载文件!还用了 System.Drawing APIs 重新定议了图象, 同时还在图片上加上你的文字,我是用 C#编写的 -- 你也可以用VB、Jscript来写。
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script language="C#" runat=server>
void UploadBtn_Click(Object sender, EventArgs e)
{
UploadFile.PostedFile.SaveAs(Server.MapPath("http://www.aspcool.com/lanmu/test.jpg"));
ImageEditor.Visible = true;
}
void UpdateBtn_Click(Object sender, EventArgs e)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("http://www.aspcool.com/lanmu/test.jpg"));
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("Lucida Sans Unicode", 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("http://www.aspcool.com/lanmu/test.jpg"), ImageFormat.JPEG);
}
</script>
<body>
<form enctype="multipart/form-data" runat=server>
<h3>
选择要上载的文件:
<input type=file runat=server>
<asp:button text="Upload Me!" runat=server/>
<hr>
<asp:panel visible=false runat=server>
<img src="http://www.aspcool.com/lanmu/test.jpg">
<h3>
图象的宽度: <asp:textbox runat=server/>
图象的高度: <asp:textbox runat=server/>
<br>
文字的内容: <asp:textbox runat=server/>
文字的大小: <asp:dropdownlist 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>
<asp:button text="Update Image" runat=server/>
</h3>
</asp:panel>
</form>
</body>
</html >