Support Forums
[Source] Tricks Using PictureBox Control [VB.NET] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Source] Tricks Using PictureBox Control [VB.NET] (/showthread.php?tid=11380)



[Source] Tricks Using PictureBox Control [VB.NET] - Fragma - 08-18-2010

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


RE: [Source] Zooming With PictureBox Control [VB.NET] - DeFacto - 08-18-2010

Thanks for this tutorial.
This can be helpful for Photo Viewer. Oui


RE: [Source] Tricks Using PictureBox Control [VB.NET] - .Nielz - 08-19-2010

This is some amazing functions :o Nice work !


RE: [Source] Tricks Using PictureBox Control [VB.NET] - Buzz Lightyear - 08-19-2010

That's downright sexy! Thanks man!


RE: [Source] Tricks Using PictureBox Control [VB.NET] - mmki - 08-20-2010

Nice bro Smile
Everyone seems to be posting about photoviewers latley


RE: [Source] Tricks Using PictureBox Control [VB.NET] - -BoodyE- - 08-21-2010

Thanks mate for this. Great source Big Grin


RE: [Source] Tricks Using PictureBox Control [VB.NET] - Fragma - 08-21-2010

Glad you all found this useful.


RE: [Source] Tricks Using PictureBox Control [VB.NET] - thanasis2028 - 08-27-2010

Can you explain the rotate part? I find it hard to understand and I don't like just copy-pasting code.


RE: [Source] Tricks Using PictureBox Control [VB.NET] - ƃu∀ ıʞƃu∀ - 11-25-2012

thanks for the tutorial

very useful Smile