how to resize a image thtz lager than picturebox??

Recommended Answers

All 6 Replies

Are you asking to Re-size the Image it's self OR change the SizeMode/BackgroundImageLayout of the PictureBox, depending if the image is larger than the PictureBox.Size?

>how to resize a image thtz lager than picturebox??

You can use SizeMode property of picture control.



You can try this:

'following code resizes picture to fit

        Dim bm As New Bitmap(PictureBox1.Image)
        Dim x As Int32 'variable for new width size
        Dim y As Int32 'variable for new height size

        Dim width As Integer = Val(x) 'image width. 

        Dim height As Integer = Val(y) 'image height

        Dim thumb As New Bitmap(width, height)

        Dim g As Graphics = Graphics.FromImage(thumb)

        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic

        g.DrawImage(bm, New Rectangle(0, 0, width, height), New Rectangle(0, 0, bm.Width, _
bm.Height), GraphicsUnit.Pixel)


      'image path. better to make this dynamic. I am hardcoding a path just for example sake
        thumb.Save("C:\newimage.bmp", _
System.Drawing.Imaging.ImageFormat.Bmp) 'can use any image format 



        Me.Close()  'exit app
commented: thnx for the reply :) work fine +1

Hi y2kshane,

Thanks for the reputation points.
If that solved your problem mark it as solved.

How can i set a default size for an image in vb dotnet. i simply want to make a image resizer software

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.