Mar 20th, 2005, 12:22 PM
#1
Thread Starter
Lively Member
Rotate an image [Resolved]
Does anybody know how I could rotate an image by degrees, kind of like in PowerPoint, Word, or Photoshop?
I know that I can use the PaintPicture Method to flip the image by 90, 180, or 270 degrees.
Thanks!
Last edited by UTGrim; Mar 20th, 2005 at 01:47 PM .
Mar 20th, 2005, 12:27 PM
#2
Re: Rotate an image
This should help ya do it in real time using DirectX8. However, if ya want to learn how to do it using regular API's, these other people might help you with that, but it's slow and still a bit advanced.
Attached Files
Mar 20th, 2005, 12:27 PM
#3
Mar 20th, 2005, 12:31 PM
#4
Re: Rotate an image
Something like this could work too (API, no DX):
VB Code:
Const SRCCOPY = &HCC0020
Const Pi = 3.14159265359
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
Private Declare Function StretchBlt% Lib "GDI32" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)
' add three command buttons and two pictureboxes. Load a bitmap into picture1 in design
' mode. Set both box to the same size. Routines execute 3 times faster than routines
' found in Microsoft's Knowledge Base.
'Sub Form_Load ()
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
'End Sub
'Sub Command1_Click ()
'flip horizontal
picture2.Cls
px% = picture1.ScaleWidth
py% = picture1.ScaleHeight
retval% = StretchBlt(picture2.hDC, px%, 0, -px%, py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
'End Su
'Sub Command2_Click ()
'flip vertical
picture2.Cls
px% = picture1.ScaleWidth
py% = picture1.ScaleHeight
retval% = StretchBlt(picture2.hDC, 0, py%, px%, -py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
'End Sub
'Sub Command3_Click ()
'rotate 45 degrees
picture2.Cls
Call bmp_rotate(picture1, picture2, 3.14 / 4)
'End Sub
'Sub bmp_rotate (pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
' bmp_rotate(pic1, pic2, theta)
' Rotate the image in a picture box.
' pic1 is the picture box with the bitmap to rotate
' pic2 is the picture box to receive the rotated bitmap
' theta is the angle of rotation
Dim c1x As Integer, c1y As Integer
Dim c2x As Integer, c2y As Integer
Dim a As Single
Dim p1x As Integer, p1y As Integer
Dim p2x As Integer, p2y As Integer
Dim n As Integer, r As Integer
c1x = pic1.ScaleWidth \ 2
c1y = pic1.ScaleHeight \ 2
c2x = pic2.ScaleWidth \ 2
c2y = pic2.ScaleHeight \ 2
If c2x < c2y Then n = c2y Else n = c2x
n = n - 1
pic1hDC% = pic1.hDC
pic2hDC% = pic2.hDC
For p2x = 0 To n
For p2y = 0 To n
If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x)
r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
p1x = r * Cos(a + theta!)
p1y = r * Sin(a + theta!)
c0& = GetPixel(pic1hDC%, c1x + p1x, c1y + p1y)
c1& = GetPixel(pic1hDC%, c1x - p1x, c1y - p1y)
c2& = GetPixel(pic1hDC%, c1x + p1y, c1y - p1x)
c3& = GetPixel(pic1hDC%, c1x - p1y, c1y + p1x)
If c0& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&)
If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&)
If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&)
If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&)
Next
t% = DoEvents()
Next
'End Sub
Mar 20th, 2005, 01:30 PM
#5
Thread Starter
Lively Member
Re: Rotate an image
Originally Posted by
NoteMe
Something like this could work too (API, no DX):
Cool! I can do some nice effects with this one.
Mar 20th, 2005, 02:25 PM
#6
Re: Rotate an image [Resolved]
No problem, just happy to help out.
ØØ
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width