<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form runat="server">
<INPUT NAME="file" TYPE="file" ID="fileup" SIZE="20" RUNAT="server">
<asp:Button runat="server" Text="确定" OnClick="ok_Click"/>
</form>
</body>
</html>
<script language="vb" runat="server">
'以下语句从网上抄来 一字未改 到底怎么改 我改了N次都出错
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
'''''判定上传图片的大小
If filename.PostedFile.FileName <> "" Then
Dim tempfilename As String
'高质量图像名称
Dim imagefilename As String = Server.MapPath(".") & "\image\" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & Now.Hour.ToString & Now.Minute & Now.Second.ToString & ".gif"
tempfilename = filename.PostedFile.FileName '原始图像
''大图生小图,生成统计长度
Dim image As System.Drawing.Image
image = System.Drawing.Image.FromFile(tempfilename)
If image.Width > 400 Or image.Height > 300 Then ''''设置是否要生成略缩图
'’取得图像大小的位置
Dim size As System.Drawing.Size
size = New System.Drawing.Size(300, 200)
'新建一个图片()
Dim ibitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(size.Width, size.Height)
'新建一个画版
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(ibitmap)
'设置高质量插值法
g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.High
'设置高质量,低速度呈现平滑程度
g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
g.Clear(Color.Blue)
'在指定位置画图片
g.DrawImage(image, New System.Drawing.Rectangle(0, 0, ibitmap.Width, ibitmap.Height), _
New System.Drawing.Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel)
ibitmap.Save(imagefilename,System.Drawing.Imaging.ImageFormat.Gif)'将图像上传保存到当前目录下的image文件夹
g.Dispose()'清空画刷
End If
End If
End Sub
</script>