Support Forums

Full Version: [Source] Tricks Using PictureBox Control [VB.NET]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thought this may be helpful to some.. A few things that you can do using a PictureBox control:

Zoom Out:
Code:
Try
            Dim scale_factor As Single = Single.Parse(2)
            Dim source As New Bitmap(PictureBox1.Image)
            Dim dest As New Bitmap(CInt(source.Width / scale_factor), CInt(source.Height / scale_factor))
            Dim gr_dest As Graphics = Graphics.FromImage(dest)

            gr_dest.DrawImage(source, 0, 0, _
                dest.Width + 1, _
                dest.Height + 1)

            PictureBox1.Image = dest
        Catch
        End Try

Zoom In:
Code:
Try
           Dim scale_factor As Single = Single.Parse(2)
            Dim source As New Bitmap(PictureBox1.Image)
            Dim dest As New Bitmap(CInt(source.Width * scale_factor), CInt(source.Height * scale_factor))
            Dim gr_dest As Graphics = Graphics.FromImage(dest)

            gr_dest.DrawImage(source, 0, 0, _
                dest.Width + 1, _
                dest.Height + 1)

            PictureBox1.Image = dest
        Catch
        End Try

Rotate:
Code:
Dim wid As Integer
        Dim hgt As Integer
        Dim X As Integer
        Dim Y As Integer
        Dim input As New Bitmap(PictureBox1.Image)
        wid = input.Width
        hgt = input.Height
        Dim output As New Bitmap(hgt, wid)

        For X = 0 To wid - 1
            For Y = 0 To hgt - 1
                output.SetPixel(hgt - Y - 1, X, _
                    input.GetPixel(X, Y))
            Next Y
        Next X

        PictureBox1.Image = output

Thanks,

- Jack
Thanks for this tutorial.
This can be helpful for Photo Viewer. Oui
This is some amazing functions :o Nice work !
That's downright sexy! Thanks man!
Nice bro Smile
Everyone seems to be posting about photoviewers latley
Thanks mate for this. Great source Big Grin
Glad you all found this useful.
Can you explain the rotate part? I find it hard to understand and I don't like just copy-pasting code.
thanks for the tutorial

very useful Smile