<%@ Page Language="VB" Debug="true"%>
 <%@ Import Namespace =Namespace="System.IO"%>
 <%@ Import Namespace =Namespace="System.Web"%>
 <%@ Import Namespace =Namespace="System.Drawing" %>
 <%@ Import Namespace =Namespace="System.Drawing.Imaging" %>
<script runat ="server">
 Sub UploadPicture_Click()Sub UploadPicture_Click( sender as Object, e as EventArgs )
If not myFile.PostedFile is Nothing then
Try
Dim strImageType as String = myFile.PostedFile.ContentType
Dim ImageStream as Stream = myFile.PostedFile.InputStream
Dim sImage as System.Drawing.Image = System.Drawing.Image.FromStream(ImageStream)
dim intPicWidth as Integer = sImage.Width
dim intPicHeight as Integer = sImage.Height
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)
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 = "loadpic/"
dim strNewFilePath as string =strFileFolder + strNewName
Dim wImageFile as string = Server.MapPath("pic/sohu.gif")
Dim wImage as System.Drawing.Image = System.Drawing.Image.FromFile(wImageFile)
Dim g as Graphics = Graphics.FromImage(sImage)
g.DrawImage(wImage, new Rectangle(50, 50, wImage.Width, wImage.Height), 0, 0, wImage.Width, wImage.Height, GraphicsUnit.Pixel)
sImage.save(Server.MapPath(strNewFilePath), imageformat.jpeg) 'save image
ImageEditor.Visible = "true"
Image1.Visible="true"
Image1.ImageUrl = ".\loadpic\" & strNewName
Catch
lblWrong.Text = "Wrong"
ImageEditor.Visible="false"
End Try
End If
End Sub
</script>
<form runat="server"><h3>
UpLoad Image: <input id="myFile" type="file" runat="server">
<asp:button Text="Upload Me!" OnClick="UploadPicture_Click" runat="server"/><P>
<asp:label id="lblWrong" runat="server" EnableViewstate="false"/>
<asp:panel id="ImageEditor" Visible="true" runat=server>
<asp:Image ID="Image1" runat="server" visible="false"/>
</asp:panel>
</form>
发表于
2005-04-23 15:51
菲一打
阅读( 626)
评论()
收藏
举报
|