|
|
|
Click here to copy the following block |
Sub ResizeImage(ByVal imgPath As String, ByVal widthPerc As Double, _ ByVal heightPerc As Double) If widthPerc <= 0 OrElse heightPerc <= 0 Then Throw New ArgumentException("widthPerc AND heightPerc arguments must be " _ & "positive values") End If
Dim currWidth, currHeight As Integer Dim newWidth, newHeight As Integer Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(imgPath) currWidth = img.Width currHeight = img.Height img.Dispose() newWidth = currWidth * widthPerc / 100 newHeight = currHeight * heightPerc / 100 ResizeImage(imgPath, newWidth, newHeight) End Sub
Sub ResizeImage(ByVal imgPath As String, ByVal width As Integer, _ ByVal height As Integer) If width <= 0 AndAlso height <= 0 Then Throw New ArgumentException("Width and/or Height arguments must be " _ & "positive integers") End If
Dim imgFormat As System.Drawing.imaging.ImageFormat = GetImageFormat _ (imgPath) Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(imgPath)
If width <= 0 OrElse height <= 0 Then If width <= 0 Then width = img.Width / (img.Height / height) ElseIf height <= 0 Then height = img.Height / (img.Width / width) End If End If
Dim bmp As New System.Drawing.Bitmap(width, height) Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage( _ DirectCast(bmp, System.Drawing.Image)) g.DrawImage(img, 0, 0, width, height) img.Dispose() bmp.Save(imgPath, imgFormat) bmp.Dispose() End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|