Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Image Resizing...

Posted on 2004-11-10
10
Medium Priority
?
406 Views
Last Modified: 2013-11-19
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????
0
Comment
Question by:niki_kiran
10 Comments
 
LVL 6

Expert Comment

by:mrwebdev
ID: 12546658
Look here... maybe this can help?
http://www.developerfusion.com/show/2569/2/
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12547445
>>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
 
LVL 2

Expert Comment

by:mcdown75
ID: 12547598
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:niki_kiran
ID: 12548105
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
 

Author Comment

by:niki_kiran
ID: 12554863
Can some one help me out on this matter?????
0
 

Author Comment

by:niki_kiran
ID: 12559236
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
 
LVL 2

Expert Comment

by:mcdown75
ID: 12565363
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
 

Author Comment

by:niki_kiran
ID: 12569390
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
 
LVL 2

Accepted Solution

by:
mcdown75 earned 750 total points
ID: 12583590
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
 

Expert Comment

by:momentuminfotech
ID: 13833463
IT does not work with GIF files
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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