Public Sub RotatePicture(fr_pic As PictureBox, to_pic As _
PictureBox)
Dim fr_pixels() As RGBTriplet
Dim to_pixels() As RGBTriplet
Dim bits_per_pixel As Integer
Dim fr_wid As Long
Dim fr_hgt As Long
Dim to_wid As Long
Dim to_hgt As Long
Dim X As Integer
Dim Y As Integer
' Get the picture's image.
GetBitmapPixels fr_pic, fr_pixels, bits_per_pixel
' Get the picture's size.
fr_wid = UBound(fr_pixels, 1) + 1
fr_hgt = UBound(fr_pixels, 2) + 1
to_wid = fr_hgt
to_hgt = fr_wid
' Size the output picture to fit.
to_pic.Width = to_pic.Parent.ScaleX(fr_hgt, vbPixels, _
to_pic.Parent.ScaleMode) + _
to_pic.Width - to_pic.ScaleWidth
to_pic.Height = to_pic.Parent.ScaleY(fr_wid, vbPixels, _
to_pic.Parent.ScaleMode) + _
to_pic.Height - to_pic.ScaleHeight
' Copy the pixels rotated 90 degrees.
ReDim to_pixels(0 To to_wid - 1, 0 To to_hgt - 1)
For X = 0 To fr_wid - 1
For Y = 0 To fr_hgt - 1
to_pixels(to_wid - Y - 1, X) = fr_pixels(X, Y)
Next Y
Next X
' Display the result.
SetBitmapPixels to_pic, bits_per_pixel, to_pixels
' Make the image permanent.
to_pic.Refresh
to_pic.Picture = to_pic.Image
End Sub
|