Image Handling Suggestions

Sumo

Member
Joined
Jun 14, 2005
Messages
10
Programming Experience
Beginner
I need to be able to resize images in an app and then save them with the new resolution. The Image object I am using takes it's size params from the image loaded from the disk and then the height/width params are read-only.

I'm sure .Net provides a method to alter/resize the image, I just can't find. Can anyone suggest a good technique? Thanks.
 
Resize PictureBox

I'm not sure I understand your question. Can you give more description on what are you trying to acomplish plz?
If you want to only make image's size to be same with the size of pictureBox or vica versa (make pictureBox's size to be same with Image size) then it's easy.

Take a look at the attached project ... Otherwise, feel free to ask for more help.

Cheers ;)
 

Attachments

  • ImageSIze.zip
    34.8 KB · Views: 77
GetThumbnail renders are very crappy above a hundred pixels or so. Try it if you don't believe me! :)

I want to take images straight from a digital camera, 2-3,000 pixels a side or so and resize them down to 400 or so pixels a side. I already have the logic to determine how large so that's not an issue. I just need a process/app/code/magic trinket that will do the resizing for me and keep them looking good.
 
Well, this is the code ... below i attached the project as well ... Cheers ;)


PHP:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
Dim xOldBmp As Bitmap
 
xOldBmp = Image.FromFile(Application.StartupPath & "\test.jpg")
 
PictureBox1.Image = xOldBmp
 
Dim xNewBmp As Bitmap = New Bitmap(220, 180, Imaging.PixelFormat.Format24bppRgb)
 
Dim xGraphics As Graphics
 
xGraphics = Graphics.FromImage(xNewBmp)
 
'this is where you set up InterpolationMode property for higher quality resizing.
 
xGraphics.InterpolationMode = Drawing2D.InterpolationMode.High
 
xGraphics.DrawImage(xOldBmp, 0, 0, 220, 180)
 
xNewBmp.Save(Application.StartupPath & "\resized.jpg")
 
MessageBox.Show("DONE")
 
Dim myp As Process
 
myp.Start(Application.StartupPath & "\resized.jpg")
 
End Sub

 

Attachments

  • SaveAsImage.zip
    70.2 KB · Views: 69
This looks pretty good Kul. Let me test it out and I'll let you know. Thanks so much! As always this forum rox!
 
Absolutely Kul!

Now I have one more request for the above code. I need the x,y sizes of the new BMP to be set as variables. Remember, I have a whole directory of images and when I resize them I need to keep x,y ratios intact. I have the numbers the height and width need to be, I just need to pass that to this statement:

Dim xNewBmp As Bitmap = New Bitmap(220, 180, Imaging.PixelFormat.Format24bppRgb)

Needs to be this:

Dim xNewBmp As Bitmap = New Bitmap(intX, intY, Imaging.PixelFormat.Format24bppRgb)

Ideas?
 
Am not sure about the Q but i will try some sugestion anyway ... sorry if it's not what you are expecting ...

Dim intX As Integer = xOldBmp.Width / 2

Dim intY As Integer = xOldBmp.Height / 2

Dim xNewBmp As Bitmap = New Bitmap(intX, intY, Imaging.PixelFormat.Format24bppRgb)


this above will reduce half of the image with proper ratio


Cheers ;)
 
Kul, thanks much. I needed to pass the variables to the Sub in order for it to be realized. Thanks again and if you're ever in North Texas I owe you a beer or a Starbucks!
 
Back
Top