C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Images »

Resize an image's dimensions and Save it as a file in different extension


Posted Date: 13 Jun 2009    Resource Type: Code Snippets    Category: Images
Author: Viji RAJKUMARMember Level: Diamond    
Rating: 1 out of 5Points: 10



The following VB.NET code is used to resize the dimensions of an image file dynamically and save it as a file in different extension.

For example, we may want to resize the dimensions of a set of image files(1024 x 1024 jpg images) from a folder into 600 x 600 and save it as a bmp files.

We need to resize the image without affecting the quality of the image.


Code to resize an image and save it as a file in different extension:


Private Sub btnResize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResize.Click

'Original Image
Dim img As New Bitmap("C:\Users\Raj\Desktop\Niagara_Pictures\DSC06721.JPG")

OrigPictureBox.Image = img

Dim resizedImg As Image = Nothing

'Resize the Image to 300 x 300 dimension
resizedImg = ResizeImage(img, 300, 300)


If Not resizedImg Is Nothing Then


ResizedPictureBox.Image = resizedImg

'Save the Image file in different extension (.bmp)
'You can use OpenFileDialog to get the File Name


resizedImg.Save("E:\Test.bmp", Imaging.ImageFormat.Bmp)

End If


End Sub

//Function to return the resized image
Private Function ResizeImage(ByVal img As Image, ByVal NewWidth As Integer, ByVal NewHeight As Integer) As Image

Dim resizedImg As Image = Nothing
Try
Dim bmp As Bitmap = New Bitmap(NewWidth, NewHeight)
Dim gr As Graphics = Graphics.FromImage(bmp)
//Resize the image without affecting the quality
gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
gr.DrawImage(img, 0, 0, Width, Height)

resizedImg = bmp

Catch ex As Exception
resizedImg = Nothing
End Try

Return resizedImg

End Function



The final image will be with the new dimensoins but with high quality.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Resize an image's dimensions and Save it as a file in different extension  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Convert An Image to Thumbnail In VB .Net
Previous Resource: Retrieve images from database in a gridview
Return to Discussion Resource Index
Post New Resource
Category: Images


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use