?
Solved

image manipulation in vb.net

Posted on 2006-05-25
1
Medium Priority
?
485 Views
Last Modified: 2006-11-18
Hi

I need to get an image (jpeg or gif) resize it and then save it as a jpeg

I have seen various ways to do this on the internet and I have a few questions...

Most of the methods i have seen involve creating a bitmap object based on the original file and then manipulating it.

Can i create a bitmap object from both  gif and jepg?
Can i save a bitmap as both a gif and a jpeg?

How can i tell the file that I am resizing is actaully a valid jpg or gif or not something that has been wrongly named or something?

Also, how can i best maintain the image quality. I need to maintain the aspect ratio best as possible. Most examples i have seen let you specify the height and the width of the new image and then resize. I was thinking I could specify a maximum height and a maximum width and resize the image as best as possible within those maximum values.

Any advice much appreciated.

Thanks a lot
andrea
0
Comment
Question by:andieje
1 Comment
 
LVL 6

Accepted Solution

by:
neilprice earned 2000 total points
ID: 16762305
This is some code to re-size a jpeg image:

        Dim factor As Double = 2.5
        Dim myImage As Bitmap = New System.Drawing.Bitmap("c:\\testimage.jpg")
        myImage = New Bitmap(myImage, New Size(myImage.Size.Width * factor, myImage.Size.Height * factor))
        myImage.Save("c:\\resized.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

When loading it (the second line) use a try catch block to catch exceptions, that way you'll know if you have something invalid trying to be loaded rather than an image.

You can create a bitmap from all the formats listed in System.Drawing.Imaging.ImageFormat I believe, and yes gif and jpg are both covered.

Hope this helps,
Neil
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question