Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what should i add to this code to resize the images that i am saving to be of width 100px

VB
Dim extension1 As String = Path.GetExtension(Fileupload1.PostedFile.FileName)
           If extension1.ToString = ".png" Or extension1.ToString = ".jpg" Or extension1.ToString = ".bmp" Or extension1.ToString = ".gif" Then
               Dim strdir1 As String = Server.MapPath("uploads/pics/")
               Fileupload1.PostedFile.SaveAs(strdir1 & cmd_id & extension1)
               textbox2.Text = cmd_id & extension1




Thanks
Posted
Comments
ZurdoDev 15-Aug-13 7:40am    
I have used a 3rd party control in the past to do it, http://www.websupergoo.com/products.htm#ig I am not sure it is a simple thing to do in .Net.

Now, do you actually need to resize them? Or, when you display on page can you just set the width to 100 and let the browser size it?
Sergey Alexandrovich Kryukov 15-Aug-13 7:47am    
Why? This is a simply thing. Please see my answer.
As to the browser resize, this is a good point.
—SA
ZurdoDev 15-Aug-13 7:57am    
Why use a control where someone has already done this? Why not use your solution? Your solution has 5 separate links none of which are ready to use. Getting a control where someone has already done it seems a whole lot easier.
Sergey Alexandrovich Kryukov 15-Aug-13 8:09am    
You underestimate the hassles of using 3rd-party. "My" solutions is extremely easy (what, do you want to protect OP from some work and practicing? :-) and uses only .NET FCL which is already there...
—SA
ZurdoDev 15-Aug-13 8:37am    
I recommended that one because I have used it and it is very easy. There certainly is value in writing the code yourself so I am not at all discounting your solution. I am just pointing out that there is no issue with my suggestion.

This is called resampling.

Read the image using the class System.Drawing.Bitmap and create a brand new image of required size:
http://msdn.microsoft.com/en-us/library/0cbhe98f.aspx[^],
http://msdn.microsoft.com/en-us/library/7we6s1x3.aspx[^].

For this new image, obtain the instance of System.Drawing.Graphics; it can be used to draw on the image:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].

Draw original image on the second one, with appropriate resize, using the Graphic instance obtained on the previous step. First of all, choose the quality of interpolation for resampling:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.interpolationmode.aspx[^].

And draw: http://msdn.microsoft.com/en-us/library/yws82c40.aspx[^].

You should remember that resampling bitmaps can only be good if you reduce the size, in worst case, enlarge, but only slightly. Any considerable enlargement will give bad quality, pixellation.

—SA
 
Share this answer
 
v2
Firstly, stop calling ToString on items which are already String - it isn't needed, it wastes time and resources, and it looks like you don't know what you are doing! :laugh:

In order to resize an image, you have to first load it as an image, and then re-draw it to a different size. Assuming you already know how to convert your data to an image of some form, the Image class has a method Image.GetThumbnailImage which does all the work for you - it proportionally resizes the image into the rectangle you want, maintaining the aspect ratio: MSDN[^]
The link includes an example.
 
Share this answer
 
Comments
[no name] 15-Aug-13 8:53am    
the getthumbelnail isnt working
OriginalGriff 15-Aug-13 9:46am    
Well, that's a helpful error description!
I'll just get out my really, really, powerful telescope and try to work out where in the world you are, and I'll see if I can see what the problem is from your screen...no, don't move like that, your head gets in the way...
Check out my answer to this similar question:

Graphics, Image Manipulation in VB.NET

I provide a class you can use to do what you need.

Hope this helps,

- Pete
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900