Generate Thumbnail Images with .NET Image Class and Visual Basic 2005
description Article and source code that shows how to generate scaled thumbnail images using the .NET Image Class, Visual Basic 2005, and Visual Studio 2005.
get resource -> Generate Thumbnail Images with .NET Image Class and Visual Basic 2005
environment Visual Studio 2005
language Visual Basic 2005
namespace System.Drawing
tags thumbnail,image,scale

You can use the .NET 2.0 Image class' GetThumbnailImage method to generate a scaled thumbnail of an image.

If the Image contains an embedded thumbnail image, this method retrieves the embedded thumbnail and scales it to the requested size. If the Image does not contain an embedded thumbnail image, this method creates a thumbnail image by scaling the main image.

Screen Shots


Example Code

 

Private Sub GetThumbnail(ByVal pathToImageFile As String, ByVal scaleToPercent As Decimal)

 

    ' Declare a variable named imageAjustmentPercent of type Decimal.

    Dim imageAdjustmentPercent As Decimal

 

    ' Divide the scaleToPercent passed into this method by 100;

    '    assign the result to the imageAjustmentPercent variable.

    imageAdjustmentPercent = CDec(scaleToPercent / 100)

 

    ' Declare two variables of type Integer named

    '    adjustedImageWidth and adjustedImageHeight.

    Dim adjustedImageWidth, adjustedImageHeight As Integer

 

    ' Declare a variable named theImage of type Image.

    Dim theImage As Image

 

    ' Get an image object from the image file;

    '    assign the image object to the theImage variable.

    theImage = Image.FromFile(pathToImageFile)

 

    ' Calculate adjustedImageWidth and adjustedImageHeight using the imageAdjustmentPercent.

    adjustedImageWidth = CType(theImage.Width * imageAdjustmentPercent, Integer)

    adjustedImageHeight = CType(theImage.Height * imageAdjustmentPercent, Integer)

 

    ' Call the Image class' GetThumbnail method to create a new scaled

    '   image object from the orginal image object. Assign it to theImage varable.

    theImage = theImage.GetThumbnailImage(adjustedImageWidth, adjustedImageHeight, Nothing, Nothing)

 

    ' Assign theImage to DemoPicturebox.

    Me.DemoPictureBox.Image = theImage

 

End Sub

Attached is a Visual Studio 2005 Windows Forms Visual Basic solution that demonstrates how to generate scaled thumbnail images from image files.

mike mcintyre  http://www.getdotnetcode.com

 

 

 

 

 

 

 

 

 

 



Copyright © 2001-2007 aZ Software Developers. All rights reserved.

 

.