image manipulation in

Posted on 2006-05-25
Last Modified: 2006-11-18

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
Question by:andieje
    1 Comment
    LVL 6

    Accepted Solution

    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,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now