ASP.Net Image Resizing Module

原文链接:http://www.cnblogs.com/HenryLiang/archive/2006/06/10/Image_Resizing_Module.html

今天花了半个小时写出来的,用来给System.Drawing.Image改变大小,而且在改变的同时保持原来的长宽比率。很简单,不过保存一下,以后还可以重复使用吧!
第一篇blog,自己给自己鼓励一下。ASP.Net Image Resizing Module

ASP.Net Image Resizing ModuleASP.Net Image Resizing ModulePrivate Sub ResizeImage()Sub ResizeImage(ByRef img As System.Drawing.Image, ByVal width As Integer, ByVal height As Integer, ByVal path As String, ByVal format As System.Drawing.Imaging.ImageFormat)
ASP.Net Image Resizing Module    Dim ratio As Double = (img.Width / img.Height)
ASP.Net Image Resizing Module    If ratio >= (width / height) Then
ASP.Net Image Resizing Module        Dim hd As String = (width / ratio).ToString()
ASP.Net Image Resizing Module        Dim i As Integer = hd.IndexOf(Convert.ToChar("."))
ASP.Net Image Resizing Module        If i > 0 Then
ASP.Net Image Resizing Module            Dim h As Integer = Convert.ToInt16(hd.Remove(i, hd.Length - i))
ASP.Net Image Resizing Module            height = h
ASP.Net Image Resizing Module        Else
ASP.Net Image Resizing Module            Dim h As Integer = Convert.ToInt16(hd)
ASP.Net Image Resizing Module            height = h
ASP.Net Image Resizing Module        End If
ASP.Net Image Resizing Module    ElseIf ratio < (width / height) Then
ASP.Net Image Resizing Module        Dim wd As String = (height * ratio).ToString()
ASP.Net Image Resizing Module        Dim i As Integer = wd.IndexOf(Convert.ToChar("."))
ASP.Net Image Resizing Module        If i > 0 Then
ASP.Net Image Resizing Module            Dim w As Integer = Convert.ToInt16(wd.Remove(i, wd.Length - i))
ASP.Net Image Resizing Module            width = w
ASP.Net Image Resizing Module        Else
ASP.Net Image Resizing Module            Dim w As Integer = Convert.ToInt16(wd)
ASP.Net Image Resizing Module            width = w
ASP.Net Image Resizing Module        End If
ASP.Net Image Resizing Module
ASP.Net Image Resizing Module    End If
ASP.Net Image Resizing Module    Dim imgLarge As New Bitmap(img, width, height)
ASP.Net Image Resizing Module    imgLarge.Save(path, format)
ASP.Net Image Resizing Module    imgLarge.Dispose()
ASP.Net Image Resizing Module
ASP.Net Image Resizing ModuleEnd Sub

转载于:https://www.cnblogs.com/HenryLiang/archive/2006/06/10/Image_Resizing_Module.html

上一篇:Scrapy 文件介绍


下一篇:【LGP5162】WD与积木