各位高手请指点,怎样在asp中实现把上传的图片生成缩略图

flowerriver 2003-07-18 03:07:20
各位高手请指点,怎样在asp中实现把上传的图片生成缩略图,
要求在asp下,不是在asp.net下。
...全文
133 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
flowerriver 2003-07-18
  • 打赏
  • 举报
回复
在那里能下载控件呀,怎么用的,有例子马上加分
greystar 2003-07-18
  • 打赏
  • 举报
回复
网上有这种控件。下载了
loulanlouzhu 2003-07-18
  • 打赏
  • 举报
回复
http://www.aspxcn.com/dotnetarticle/show.aspx?id=132
delphine 2003-07-18
  • 打赏
  • 举报
回复
ASP解决需要组件!!

我用组件做了一个!

http://album.topdigi.com.cn

欢迎大家去用!!
孟子E章 2003-07-18
  • 打赏
  • 举报
回复
以前,在页面上实现缩略图必须借助第三方组件。现在,有了.NET,就可以很轻松地实现缩略图。下面就是实现缩略图的例子。


代码如下:Thumbnail.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Thumbnail.aspx.vb"
Inherits="aspxWeb.Thumbnail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>在ASP.NET里轻松实现缩略图</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<asp:Label id="Label1" runat="server"></asp:Label>
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
<INPUT type="file" name="file" width="600"><br><br>
<asp:Button id="Button1" runat="server"></asp:Button>
</form>
</body>
</HTML>

后代码:Thumbnail.aspx.vb

Imports System
Imports System.Web
Imports System.Drawing
Imports System.IO
Imports System.Drawing.Imaging

Public Class Thumbnail
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "<h3>在ASP.NET里轻松实现缩略图</h3>"
Button1.Text = "上载并显示缩略图"
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFileColl As HttpFileCollection = HttpContext.Current.Request.Files
Dim MyPostedFile As HttpPostedFile = MyFileColl.Item(0)
If LCase(MyPostedFile.ContentType.ToString()).IndexOf("image") < 0 Then
Response.Write("无效的图形格式。")
Exit Sub
End If
GetThumbNail(MyPostedFile.FileName, 100, 100, MyPostedFile.ContentType.ToString(),_
False, MyPostedFile.InputStream)
End Sub

Private Function GetImageType(ByVal strContentType) As System.Drawing.Imaging.ImageFormat
Select Case (strContentType.ToString().ToLower())
Case "image/pjpeg"
GetImageType = System.Drawing.Imaging.ImageFormat.Jpeg
Case "image/gif"
GetImageType = System.Drawing.Imaging.ImageFormat.Gif
Case "image/bmp"
GetImageType = System.Drawing.Imaging.ImageFormat.Bmp
Case "image/tiff"
GetImageType = System.Drawing.Imaging.ImageFormat.Tiff
Case "image/x-icon"
GetImageType = System.Drawing.Imaging.ImageFormat.Icon
Case "image/x-png"
GetImageType = System.Drawing.Imaging.ImageFormat.Png
Case "image/x-emf"
GetImageType = System.Drawing.Imaging.ImageFormat.Emf
Case "image/x-exif"
GetImageType = System.Drawing.Imaging.ImageFormat.Exif
Case "image/x-wmf"
GetImageType = System.Drawing.Imaging.ImageFormat.Wmf
Case Else
GetImageType = System.Drawing.Imaging.ImageFormat.MemoryBmp
End Select
End Function

Private Sub GetThumbNail(ByVal strFileName, ByVal iWidth, ByVal iheight, ByVal strContentType, _
ByVal blnGetFromFile, ByVal ImgStream)
Dim oImg As Image
If blnGetFromFile Then
oImg = oImg.FromFile(strFileName)
Else
oImg = oImg.FromStream(ImgStream)
End If
oImg = oImg.GetThumbnailImage(iWidth, iheight, Nothing, (New IntPtr()).Zero)
Dim strGuid As String = (New Guid()).NewGuid().ToString().ToUpper()
Dim strFileExt As String = strFileName.Substring(strFileName.LastIndexOf("."))
'保存到本地
'oImg.Save(Server.MapPath("images") + "\" + strGuid + strFileExt, GetImageType(strContentType))
'直接输出url文件
'Response.Redirect("images/" + strGuid + strFileExt)
'以下显示在屏幕上
Response.ContentType = strContentType
Dim MemStream As New MemoryStream()
' 注意:这里如果直接用 oImg.Save(Response.OutputStream, GetImageType(strContentType))
' 对不同的格式可能会出错,比如Png格式。
oImg.Save(MemStream, GetImageType(strContentType))
MemStream.WriteTo(Response.OutputStream)
End Sub

End Class


http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=45E7E33C-F149-450E-B5D5-832958C20538
在ASP.NET里轻松实现缩略图
孟子E章 2003-07-18
  • 打赏
  • 举报
回复
以前,在页面上实现缩略图必须借助第三方组件。现在,有了.NET,就可以很轻松地实现缩略图。下面就是实现缩略图的例子。

查看例子

代码如下:Thumbnail.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Thumbnail.aspx.vb"
Inherits="aspxWeb.Thumbnail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>在ASP.NET里轻松实现缩略图</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<asp:Label id="Label1" runat="server"></asp:Label>
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
<INPUT type="file" name="file" width="600"><br><br>
<asp:Button id="Button1" runat="server"></asp:Button>
</form>
</body>
</HTML>

后代码:Thumbnail.aspx.vb

Imports System
Imports System.Web
Imports System.Drawing
Imports System.IO
Imports System.Drawing.Imaging

Public Class Thumbnail
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "<h3>在ASP.NET里轻松实现缩略图</h3>"
Button1.Text = "上载并显示缩略图"
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFileColl As HttpFileCollection = HttpContext.Current.Request.Files
Dim MyPostedFile As HttpPostedFile = MyFileColl.Item(0)
If LCase(MyPostedFile.ContentType.ToString()).IndexOf("image") < 0 Then
Response.Write("无效的图形格式。")
Exit Sub
End If
GetThumbNail(MyPostedFile.FileName, 100, 100, MyPostedFile.ContentType.ToString(),_
False, MyPostedFile.InputStream)
End Sub

Private Function GetImageType(ByVal strContentType) As System.Drawing.Imaging.ImageFormat
Select Case (strContentType.ToString().ToLower())
Case "image/pjpeg"
GetImageType = System.Drawing.Imaging.ImageFormat.Jpeg
Case "image/gif"
GetImageType = System.Drawing.Imaging.ImageFormat.Gif
Case "image/bmp"
GetImageType = System.Drawing.Imaging.ImageFormat.Bmp
Case "image/tiff"
GetImageType = System.Drawing.Imaging.ImageFormat.Tiff
Case "image/x-icon"
GetImageType = System.Drawing.Imaging.ImageFormat.Icon
Case "image/x-png"
GetImageType = System.Drawing.Imaging.ImageFormat.Png
Case "image/x-emf"
GetImageType = System.Drawing.Imaging.ImageFormat.Emf
Case "image/x-exif"
GetImageType = System.Drawing.Imaging.ImageFormat.Exif
Case "image/x-wmf"
GetImageType = System.Drawing.Imaging.ImageFormat.Wmf
Case Else
GetImageType = System.Drawing.Imaging.ImageFormat.MemoryBmp
End Select
End Function

Private Sub GetThumbNail(ByVal strFileName, ByVal iWidth, ByVal iheight, ByVal strContentType, _
ByVal blnGetFromFile, ByVal ImgStream)
Dim oImg As Image
If blnGetFromFile Then
oImg = oImg.FromFile(strFileName)
Else
oImg = oImg.FromStream(ImgStream)
End If
oImg = oImg.GetThumbnailImage(iWidth, iheight, Nothing, (New IntPtr()).Zero)
Dim strGuid As String = (New Guid()).NewGuid().ToString().ToUpper()
Dim strFileExt As String = strFileName.Substring(strFileName.LastIndexOf("."))
'保存到本地
'oImg.Save(Server.MapPath("images") + "\" + strGuid + strFileExt, GetImageType(strContentType))
'直接输出url文件
'Response.Redirect("images/" + strGuid + strFileExt)
'以下显示在屏幕上
Response.ContentType = strContentType
Dim MemStream As New MemoryStream()
' 注意:这里如果直接用 oImg.Save(Response.OutputStream, GetImageType(strContentType))
' 对不同的格式可能会出错,比如Png格式。
oImg.Save(MemStream, GetImageType(strContentType))
MemStream.WriteTo(Response.OutputStream)
End Sub

End Class


http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=45E7E33C-F149-450E-B5D5-832958C20538
在ASP.NET里轻松实现缩略图
flowerriver 2003-07-18
  • 打赏
  • 举报
回复
各位大侠帮帮我啊
相关推荐
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-18 03:07
社区公告

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

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