Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRotate a picture 90 degrees in VB .NET
Keywordsrotate, image, picture, rotation, VB .NET
CategoriesGraphics, VB.NET
 
Create a Bitmap from the input image. Create another Bitmap with the proper dimensions for the rotated result.

Use the Bitmap objects' GetPixel and SetPixel methods to copy pixel values from one to the other. Then assign the Bitmap to the output PictureBox's Image property to display the result. That control's SizeMode property is set to AutoSize so the PictureBox automatically resizes to fit the result.

 
Private Sub btnRotate_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnRotate.Click
    Dim wid As Integer
    Dim hgt As Integer
    Dim X As Integer
    Dim Y As Integer

    ' Make a Bitmap representing the input image.
    Dim bm_in As New Bitmap(picIn.Image)
    wid = bm_in.Width
    hgt = bm_in.Height

    ' Make the output bitmap.
    Dim bm_out As New Bitmap(hgt, wid)

    ' Copy the pixel values.
    For X = 0 To wid - 1
        For Y = 0 To hgt - 1
            bm_out.SetPixel(hgt - Y - 1, X, _
                bm_in.GetPixel(X, Y))
        Next Y
    Next X

    ' Display the result.
    picOut.Image = bm_out
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated