Resizing Images... 
Author Message
 Resizing Images...

What are some different ways to resize images in Visual Basic .net?
What are the advantages / disadvantages of each of these ways?
Which way reains the best quality?

P.S. All the images this program will be sizing will usually need to be
sized from resoultions like 2048 px X 2000 px down to 350px X 200px..

--
Matt MacLean
__________



Mon, 31 Jan 2005 10:51:02 GMT  
 Resizing Images...
Hi Matt,

Two options that I've worked with are CreateThumbnail and DrawImage.
CreateThumbnail works quite well unless the image already has a built-in
thumbnail (e.g., from a digital camera). In that case, the function resizes
the thumbnail rather than the original image. Here's some code from my book:

Private Sub CreateThumbnail_Click(ByVal sender As System.Object, ByVal e As
_
 System.EventArgs) Handles CreateThumbnail.Click

 ' Makes a Thumbnail of the Graphic Selected in ComboBox2
 Dim imageName As String = ComboBox2.Text
 Dim bitmapID As Bitmap
 Dim bitmapPath As String = String.Concat(Application.StartupPath,
"\graphics\", _
  imageName)

 If System.IO.File.Exists(bitmapPath) = True Then
  bitmapID = New Bitmap(bitmapPath)
  Dim thumbnailID As Image = bitmapID.GetThumbnailImage(PictureBox1.Width, _
   PictureBox1.Height, Nothing, IntPtr.Zero)
  PictureBox1.Image = thumbnailID
 Else
  MessageBox.Show("You must select an External Image first.")
 End If
End Sub

Some DrawImage code:

' Override the OnPaintBackground method to resize BackgroundImage
Protected Overrides Sub OnPaintBackground(ByVal pevent As _
 System.Windows.Forms.PaintEventArgs)

 ' Original code from Tim Overbay
 If Not (BackgroundImage Is Nothing) Then
  With pevent.Graphics
   .InterpolationMode = Drawing.Drawing2D.InterpolationMode.Bicubic
   .Clear(BackColor)
   Dim graphicWidth As Integer = Me.ClientRectangle.Width
   Dim graphicHeight As Integer = Me.ClientRectangle.Height
   .DrawImage(BackgroundImage, 0, 0, graphicWidth, graphicHeight)
   ' Tim's initial code had Width and Height but using the
   ' ClientRectangle accounts for the Title bar and window borders
  End With
 End If
End Sub

Hope this is helpful.

--
Jeff Rhodes
Author of "VBTrain.Net: Creating Computer and Web Based Training with Visual
Basic? .NET"
www.vbtrain.net
Home of the Shape and Graphical Text controls


Quote:
> What are some different ways to resize images in visual basic .net?
> What are the advantages / disadvantages of each of these ways?
> Which way reains the best quality?

> P.S. All the images this program will be sizing will usually need to be
> sized from resoultions like 2048 px X 2000 px down to 350px X 200px..

> --
> Matt MacLean
> __________



Tue, 01 Feb 2005 00:55:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. upload image AND resize image to 280x210

2. Resize Image (Twips)

3. Some kind of addin to resize image

4. resizing image files

5. Resizing images using GetThumbnailImage or DrawImage

6. VB - How 2 learn 2 resize images at runtime

7. Resize Image

8. Resize image control

9. Resizing Image In RichTextBox

10. Resize image?

11. Resize Image file !

12. Rotating and resizing images

 

 
Powered by phpBB® Forum Software