Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 148,654 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,484 people online right now. Registration is fast and FREE... Join Now!





Resize Image

Resizes Image to desired size

Submitted By: spimoles
Actions:
Rating:
Views: 16,025

Language: VB.NET

Last Modified: October 22, 2006
Instructions: Use as Function. Resizes image in a Picture Box

Snippet


  1.         'following code resizes picture to fit
  2.  
  3.         Dim bm As New Bitmap(PictureBox1.Image)
  4.         Dim x As Int32 'variable for new width size
  5.         Dim y As Int32 'variable for new height size
  6.  
  7.         Dim width As Integer = Val(x) 'image width.
  8.  
  9.         Dim height As Integer = Val(y) 'image height
  10.  
  11.         Dim thumb As New Bitmap(width, height)
  12.  
  13.         Dim g As Graphics = Graphics.FromImage(thumb)
  14.  
  15.         g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  16.  
  17.         g.DrawImage(bm, New Rectangle(0, 0, width, height), New Rectangle(0, 0, bm.Width, _
  18. bm.Height), GraphicsUnit.Pixel)
  19.  
  20.         g.Dispose()
  21.  
  22.  
  23.       'image path. better to make this dynamic. I am hardcoding a path just for example sake
  24.         thumb.Save("C:\newimage.bmp", _
  25. System.Drawing.Imaging.ImageFormat.Bmp) 'can use any image format
  26.  
  27.         bm.Dispose()
  28.  
  29.         thumb.Dispose()
  30.  
  31.         Me.Close()  'exit app
  32.  

Copy & Paste


Comments


realwish 2008-03-29 03:46:23

not easy to understand for a beginner

csee85 2008-05-04 05:54:05

NOOB

jagatworld 2008-05-16 23:17:16

really good......

jacobjordan 2008-12-31 13:48:16

This is good to demonstrate the concept of how to use Graphics to resize an image, and i have referenced it many times when providing help to people in VB.NET who need to do so. However, it is very unclear and poorly written, and needs much more explaining and commenting on your part. My 2 cents.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month