Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

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





Resize Image

Resizes Image to desired size

Submitted By: spimoles
Actions:
Rating:
Views: 14,712

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......


Add comment


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





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month