我知道在上传图片时,可以保存原图,也可缩略处理后保存,也可同时保存原图和缩略图,在供页面调用的时候,根据要求输出原图或缩略图。
我现在有个疑问,能不能在上传图片时只保存原图,不作任何缩略处理,在页面调用时,图片输出就能自动进行动态缩略,请问有没有通过某种方法来实现的可能呢?如果有这种处理方法的话,不知道占用系统资源是不是很厉害?
请大家谈谈经验,谢谢!

解决方案 »

  1.   

    之前写的VB.NET 的ASP.NET取得图片的代码 
    GetImage.aspx <%@ Page Language="VB" AutoEventWireup="false" CodeFile="GetImage.aspx.vb" Inherits="GetImage" %><!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 runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    <%
    response.clear
                Call sendFile()response.end
    %>     
        </div>
        </form>
    </body>
    </html>
    GetImage.aspx.vb Partial Class GetImage    Inherits System.Web.UI.Page
        '在内存中绘图
        '作者:武广敬
        Sub sendFile()
            Dim PicMode As String = Request.QueryString("m")
            Dim PicFolder As String
            Dim ImageSize = CInt(Request("s"))
            If PicMode = "" Then
                PicMode = "p"
            End If
            Select Case PicMode
                Case "p"
                    PicFolder = "image/picpro/"
                Case "n"
                    PicFolder = "Image/Picnews/"
                Case Else
                    PicFolder = "image/picpro/"
            End Select
            If File.Exists(Server.MapPath(PicFolder & Request("id") & ".jpg")) And Request("s") <> "" And Request("s") < 10000 And Request("s") > 0 Then
                Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(PicFolder & Request("id") & ".jpg"))
                Dim thisFormat = g.RawFormat            Dim ImageWidth As Integer = ImageSize
                Dim ImageHeight As Integer = ImageSize
                If g.Width > ImageSize Or g.Height > ImageSize Then
                    If g.Width > g.Height Then
                        ImageHeight = CInt((ImageHeight / g.Width) * g.Height)                Else
                        ImageWidth = CInt((ImageSize / g.Height) * g.Width)                End If
                Else
                    ImageWidth = g.Width
                    ImageHeight = g.Height
                End If            Dim imgOutput As New System.Drawing.Bitmap(g, ImageWidth, ImageHeight)
                If thisFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif) Then
                    Response.ContentType = "image/gif"
                Else
                    Response.ContentType = "image/jpeg"
                End If
                imgOutput.Save(Response.OutputStream, thisFormat)
                g.Dispose()
                imgOutput.Dispose()
            Else
                Call SendError()
            End If
        End Sub
        '如果图片不存在,动态绘制一个No Image的图片
        Sub SendError()
            Dim imgOutput As New System.Drawing.Bitmap(120, 120, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(imgOutput)
            g.Clear(System.Drawing.Color.White)
            g.DrawString("No Image", New System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold), System.Drawing.SystemBrushes.WindowText, New System.Drawing.PointF(2, 2))
            Response.ContentType = "image/gif"
            imgOutput.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
            g.Dispose()
            imgOutput.Dispose()
        End Sub
    End Class
    调用方法 
    getimage.aspx?id=799&s=1600 
    799为文件名 
    1600为文件显示的尺寸. 
    可以动态生成缩图. 
    如果文件不存在的话 
    就显示No Image的图片 
    供你参考