Dim bm_in As New Bitmap(PictureBox1.Image) ' Make an array of points defining the ' image's corners. Dim wid As Single = bm_in.Width Dim hgt As Single = bm_in.Height Dim corners As Point() = { _ New Point(0, 0), _ New Point(wid, 0), _ New Point(0, hgt), _ New Point(wid, hgt)} ' Translate to center the bounding box at the origin. Dim cx As Single = wid / 2 Dim cy As Single = hgt / 2 Dim i As Long For i = 0 To 3 corners(i).X -= cx corners(i).Y -= cy Next i ' Rotate. Dim theta As Single = Single.Parse(5) * PI / 180.0 Dim sin_theta As Single = Sin(theta) Dim cos_theta As Single = Cos(theta) Dim X As Single Dim Y As Single For i = 0 To 3 X = corners(i).X Y = corners(i).Y corners(i).X = X * cos_theta + Y * sin_theta corners(i).Y = -X * sin_theta + Y * cos_theta Next i ' Translate so X >= 0 and Y >=0 for all corners. Dim xmin As Single = corners(0).X Dim ymin As Single = corners(0).Y For i = 1 To 3 If xmin > corners(i).X Then xmin = corners(i).X If ymin > corners(i).Y Then ymin = corners(i).Y Next i For i = 0 To 3 corners(i).X -= xmin corners(i).Y -= ymin Next i ' Create an output Bitmap and Graphics object. Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin)) Dim gr_out As Graphics = Graphics.FromImage(bm_out) ' Drop the last corner lest we confuse DrawImage, ' which expects an array of three corners. ReDim Preserve corners(2) ' Draw the result onto the output Bitmap. gr_out.DrawImage(bm_in, corners) ' Display the result. PictureBox1.Image = bm_out
Panel
PictureBox
Paint
e.Graphics.RotateTransform
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)