asp.net生成高质量缩略图(VB.net)
来源:互联网 发布:rocketdock类似软件 编辑:程序博客网 时间:2024/05/22 00:09
最近给公司做一个固定资产管理的小程序,要显示固定资产的照片,显示原图的话会因图片太大而影响速度,于是就改为显示缩略图,下面的二种方法中第二种方法生成的图片很小且质量较高,原图为900K大小,第一种生成后有300K,第二种生成后只有十多K,有兴趣的可以看看。
方法一:
img_tp.ImageUrl = ""
Dim callb As System.Drawing.Image.GetThumbnailImageAbort = Nothing
Dim myimage As System.Drawing.Image
Dim newimage As System.Drawing.Image
NewImage = MyImage.GetThumbnailImage(800, 1000, callb, new System.IntPtr());
myimage = System.Drawing.Image.FromFile(Server.MapPath(xh))
newimage = myimage.GetThumbnailImage(320, 240, callb, New System.IntPtr())
newimage.Save(Server.MapPath(xh + "_.jpg"))
img_tp.ImageUrl = xh + "_.jpg"
myimage.Dispose()
newimage.Dispose()
方法二:
Public Sub MakeSLT(ByVal originalImagePath As String, ByVal thumbnailPath As String, ByVal width As Integer, ByVal height As Integer)
Dim originalImage As System.Drawing.Image = System.Drawing.Image.FromFile(originalImagePath)
Dim towidth As Integer = 0
Dim toheight As Integer = 0
If originalImage.Width > width AndAlso originalImage.Height < height Then
towidth = width
toheight = originalImage.Height
End If
If originalImage.Width < width AndAlso originalImage.Height > height Then
towidth = originalImage.Width
toheight = height
End If
If originalImage.Width > width AndAlso originalImage.Height > height Then
towidth = width
toheight = height
End If
If originalImage.Width < width AndAlso originalImage.Height < height Then
towidth = originalImage.Width
toheight = originalImage.Height
End If
Dim x As Integer = 0
'左上角的x坐标
Dim y As Integer = 0
'左上角的y坐标
'新建一个bmp图片
Dim bitmap As System.Drawing.Image = New System.Drawing.Bitmap(towidth, toheight)
'新建一个画板
Dim g As Graphics = System.Drawing.Graphics.FromImage(bitmap)
'设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High
'设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
'清空画布并以透明背景色填充
g.Clear(Color.Transparent)
'在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, x, y, towidth, toheight)
Try
'以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch e As System.Exception
Throw e
Finally
originalImage.Dispose()
bitmap.Dispose()
g.Dispose()
End Try
End Sub
使用时引用这个函数就可以了。
- asp.net生成高质量缩略图(VB.net)
- ASP.NET 生成高质量缩略图代码
- asp.net 生成高质量缩略图
- ASP.NET 生成高质量缩略图代码
- [收藏]ASP.NET生成高质量缩略图通用函数(VB.NET、c#代码)
- asp.net生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- ASP.NET生成高质量缩略图通用函数(c#代码)
- 图片文件上传, 生成高质量缩略图 (asp.net c#)
- .net等比生成高质量缩略图
- C#(.NET)生成高质量(清晰)缩略图
- 提高ASP.NET生成缩略图质量
- 为自己而工作(转)
- PM 笔记之一
- red5的入门 for linux (原创)
- 湖北多地出现阴阳天(图)
- TCP/IP 之TCP协议(4):差错控制
- asp.net生成高质量缩略图(VB.net)
- SQL Server 2005对海量数据处理
- c# 多个空格变为一个空格
- javascript 怕自己忘记了 所以记下来(date 格式化)
- reinterpret_cast翻译
- 安装VS2003遇到的问题集
- 获取数据库的sql语句
- sqlplus可以连接,pl/sql 报ORA-12154: TNS:无法解析指定的连接标志符
- oracle数据库触发器例子