惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - pigyang666_asp.net

学习方法 WIKI 胡哥的作业 最爱冬天的被窝 教育技术图库系统测试版 连续不间断横向滚动图片 希望自己能坚持 给电脑升级了512M的内存条 xml无限级分类 今天制作了一个pdf格式的文档 标准的不标准 css+div布局总结——基础篇 空间必须放在具有 runat=server 的窗体标记内 web标准的“表现和结构相分离” DBNull 到 String的强制转换 连接数据库的偷懒小技巧 对制作网站效果图的一点个人经验 我制作的网站效果图,大家给点意见:) 数据库连接的整理
以缩略图的形式显示数据库的图片
pigyang666_asp.net · 2005-09-22 · via 博客园 - pigyang666_asp.net

Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Drawing.Imaging

Imports System.IO

Public Class GetThumbnail
    
Inherits System.Web.UI.Page
  
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        
'最大长度
        Const MaxLength = 130
        
If Request.QueryString("filename"<> "" Then
'*******************这里的filename 是指存入到的文件夹中的缩略图名*********************
            '取得原图
            Dim FileName As String = Request.QueryString("filename")
            
Dim bmpOld As Bitmap = New Bitmap(Server.MapPath("uploadPhotos/" & FileName))
'*******************uploadPhotos为你存储上传图片的文件夹,一般最好建立一个专门存放文件或相册的文件夹********
            '计算缩小比例
            Dim d1 As Double
            
If bmpOld.Height > bmpOld.Width Then
                d1 
= Convert.ToDouble(MaxLength) / Convert.ToDouble(bmpOld.Width)
            
Else
                d1 
= Convert.ToDouble(MaxLength) / Convert.ToDouble(bmpOld.Height)
            
End If
            
'产生缩图
            Dim bmpThumb As Bitmap = New Bitmap(bmpOld, Convert.ToInt32(bmpOld.Width * d1), Convert.ToInt32(bmpOld.Height * d1))
            
'清除缓冲

            Response.Clear()
            
'生成图片
            bmpThumb.Save(Response.OutputStream, ImageFormat.Jpeg)
            Response.End()
            
'释放资源
            bmpThumb.Dispose()
            bmpOld.Dispose()

        
End If

        
'GetThumbNail(Server.MapPath("uploadFiles/" & Request.QueryString("filename")), 100, 100, "image/pjpeg")


    
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)
        
Dim oImg As Image
        oImg 
= oImg.FromFile(strFileName)

        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)
        MemStream.Close()
    
End Sub



End Class

最后只要到显示图片的页面的html视图里把图片显示的代码改下:

<asp:Image runat="server" BorderWidth="1px" ID="Image1" 
ImageUrl
='<%# "GetThumbnail.aspx?filename=" + trimDataBinder.EvalContainer, "DataItem.PhotoUrl")) %>' >

最后就实现了功能
备注:因为第一次总结,所以有些地方没写清楚,大家可以给我留言,我将给予修改