中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > Asp > 应用范列
上传图片并生成缩略图
作者:佚名 时间:2006-11-05 15:54 出处:Host01.Com 责编:月夜寒箫
              摘要:上传图片并生成缩略图
 Sub upimages()
Dim iname As String
If Not (fileup.PostedFile Is Nothing) Then
Dim namestr1 As String = (fileup.PostedFile.FileName)
If LCase(fileup.PostedFile.ContentType.ToString()) = "image/pjpeg" Or LCase(fileup.PostedFile.ContentType.ToString()) = "image/jpg" Then
Dim j As Integer = namestr1.LastIndexOf(".")
Dim newname As String = namestr1.Substring(j) '圖片得到後輟名
iname = CStr(Now.ToFileTimeUtc) '隨機的文件名(不會重復)
Dim newnames As String = iname + newname '重新組合文件名
Dim i As Integer = namestr1.LastIndexOf("\") + 1
Dim namestr As String = namestr1.Substring(i)
fileup.PostedFile.SaveAs(Server.MapPath(imagelocal) + "\" + newnames) '保存文件到imagelocal文件夾
'生成縮略圖()
Dim image, sImage As System.Drawing.Image
image = System.Drawing.Image.FromStream(fileup.PostedFile.InputStream)'得到原图
Dim width As Decimal = image.Width过且过'得到原图的宽
Dim height As Decimal = image.Height'得到原图的高
Dim newwidth, newheight As Integer
'设置缩略图的高和宽
If (width > height) Then
newwidth = 150
newheight = CInt(height / width * 150)
Else
newheight = 150
newwidth = CInt(width / height * 150)
End If
sImage = image.GetThumbnailImage(newwidth, newheight, Nothing, IntPtr.Zero)
Dim x As Integer = sImage.Width / 2 - 30
Dim y As Integer = sImage.Height - 20
Dim output As Bitmap = New Bitmap(sImage)
Dim g As Graphics = Graphics.FromImage(output)
' 給縮略圖加上版權信息()
Dim fonts As New Font("Courier New", 9)
g.DrawString("版權信息", fonts, New SolidBrush(Color.Red), x, y)
output.Save(Server.MapPath("Simagelocal") + "\s_" + newnames, System.Drawing.Imaging.ImageFormat.Jpeg)
'保存縮略圖到Simagelocal文件夾
Image1.Visible=true;
Image1.ImageUrl = "Simagelocal" + "\s_" + newnames

Else
Label1.Text = "請選擇jpg類型的圖片"

End If
End If
End Sub
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有