Image Resizing...

Hi...I am using the following code to resize an image....

Imports System.Drawing
Imports System.Drawing.Bitmap
Imports System.Drawing.Graphics

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim image As System.Drawing.Image = Nothing
                Dim bitmap As bitmap = Nothing
                image = System.Drawing.Image.FromFile("C:\untitled.bmp")
                bitmap = New bitmap(image, 200, 200)
                bitmap.Save(MapPath("c:\testImage"), image.RawFormat)
            Catch ex As Exception
                Response.Write(ex.Message)
            Finally              
            End Try
        End Sub

But I am getting this exception:
Exception Details: System.OutOfMemoryException: Out of memory.
Can someone help me out????
niki_kiranAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrwebdevCommented:
Look here... maybe this can help?
http://www.developerfusion.com/show/2569/2/
0
riyasjefCommented:
>>Dim bitmap As bitmap = Nothing

change the variable name "bitmap"...same as bitmap(image, 200, 200) class

OR try

http://www.plus.hr/skripte/asp.net/resize_image.html 

http://www.codeproject.com/aspnet/pnguploader.asp


RJ
0
mcdown75Commented:
This looks like vb.net.  Could it be this simple? I doubt it, but it's worth a shot

Picturebox1.width = picturebox1.width * 1.25
Picturebox1.height = picturebox1.height * 1.25

TekNik
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

niki_kiranAuthor Commented:
hey i am using this code::::

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim UploadedFile As [String] = "C:\kiran\test\universal_pay_600x400.gif"
        Dim imageHeight As Integer
        Dim imageWidth As Integer
        imageHeight = 50
        imageWidth = 150
        Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(UploadedFile)
        Dim dummyCallBack As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
        Dim thumbNailImg As System.Drawing.Image = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero)
        Response.ContentType = "image/gif"
        fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
    End Sub
    Public Function ThumbnailCallback() As Boolean
        Return False
    End Function

the image is gettting displayed. But not with the changed height and width. It's displaying the old dimensions. Can someone tell me why this is happening???
0
niki_kiranAuthor Commented:
Can some one help me out on this matter?????
0
niki_kiranAuthor Commented:
hey i got this image resizing thing working.....but after resizing the image is not clear....i mean even if i don change the image dimensions, the resolutions of the image is not good. can someone help me out with this problem. thank you
0
mcdown75Commented:
My guess would be that you are not using a good image type.  BMP's resize horribly.  Gif's can be better, Jpg's, in my opinion only, resize the best, but they are big and can take a long time to download.  Try changing the type of the image file.  Open it up in an image editor and do a save as ......   Just play with it and see which one looks the best upon resize.  Also, your screen resoultion can play a part too.  If you have your colors set to 16 or 256 colors and you put a high res picture up, it looks like doggy doo.

TekNik
0
niki_kiranAuthor Commented:
i can't use jpegs....as per my project i need to use GIF files.....even if i dont change any resolution for resizing, i mean even if i keep the original dimensions the resulting image doesn't look as good a the original...the pixels are messed up.....is there any way that i can smooth the image after this statements???

        Dim thumbNailImg As System.Drawing.Image = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero)
        Response.ContentType = "image/gif"
        fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
 
Can someone help me out here??????
0
mcdown75Commented:
Niki,

Oh, I am a dummy.  Your getting the thumbnail and enlarging it.  I think what is happening is, instead of calling the thumbnail, you need to be calling the original image.  According to my documentation, the GetThumbnailImage calls a miniature version of the image in question.  That explains why you are getting a messed up picture.  The "Lite" version of the picture pixelates when you enlarge it.

Try this:

Dim myImage as Image
img.image = Image.FromFile(myFilePath)
img.height = 400
img.width = 400

You may have to play with this a bit, but that is essential what I have that will work.

TekNik
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
momentuminfotechCommented:
IT does not work with GIF files
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.