Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Graphics/GDI+

Graphics/GDI+ Graphics discussion for VB.NET applications, Winforms, Web, Compact Framework, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2009, 11:53 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Sep 2006
Posts: 8
Reputation: 0
davco is on a distinguished programming path ahead
Smile Image resizing

I have an image resizing app and I need to keep the deminsions proportionate.
How do I do that with this code?


Private Sub Reduce(ByVal factor As Double)
img = New Bitmap(img, New Size(50, 50))
picPhoto.Image = img

Dim SizeKb As String
' To compute: size in Kb
Dim ms As New MemoryStream()
img.Save(ms, Imaging.ImageFormat.Jpeg)
SizeKb = (ms.Length \ 1024).ToString() & "Kb "

lblCurrentSize.Text = "Current Size: " & SizeKb & "(" & img.Width & "x" & img.Height & ") [" & img.Width / img.Height & "]"
End Sub
It resizes images well but doesn`t kep the width and height proportionate.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-01-2009, 2:53 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Apr 2009
Posts: 17
Reputation: 12
Shemeer is on a distinguished programming path ahead
Smile Resize image

Hi,
Try this

Private Function ResizeImage(ByVal mg As Bitmap, ByVal newSize As Size) As Bitmap
Dim ratio As Double = 0.0R
Dim myThumbWidth As Double = 0.0R
Dim myThumbHeight As Double = 0.0R
Dim x As Integer = 0
Dim y As Integer = 0

Dim bp As Bitmap


If (mg.Width / Convert.ToDouble(newSize.Width)) > (mg.Height / Convert.ToDouble(newSize.Height)) Then
ratio = Convert.ToDouble(mg.Width) / Convert.ToDouble(newSize.Width)
Else
ratio = Convert.ToDouble(mg.Height) / Convert.ToDouble(newSize.Height)
End If
myThumbHeight = Math.Ceiling(mg.Height / ratio)
myThumbWidth = Math.Ceiling(mg.Width / ratio)

Dim thumbSize As New Size(CInt(myThumbWidth), CInt(myThumbHeight))
bp = New Bitmap(newSize.Width, newSize.Height)
x = (newSize.Width - thumbSize.Width) / 2
y = (newSize.Height - thumbSize.Height)
' Had to add System.Drawing class in front of Graphics ---
Dim g As System.Drawing.Graphics = Graphics.FromImage(bp)
g.SmoothingMode = SmoothingMode.HighQuality
g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = PixelOffsetMode.HighQuality
Dim rect As New Rectangle(x, y, thumbSize.Width, thumbSize.Height)
g.DrawImage(mg, rect, 0, 0, mg.Width, mg.Height, _
GraphicsUnit.Pixel)



Return bp
End Function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
image resizer, imagedraw, resize images


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:01 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.