How to Spin a Picture
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 'Graphics - How to Spin a Picture 'Add a Timer Control and four Picture Boxes to your form and set the Timer Interval property to 10. 'Add pictures to Picture1 and Picture2. All the Pictures should be at the same size. Dim dAngle As Double Const NUM_TURNS = 36 Const PI = 3.14159265358979 Const CENTER_X = 4000 Const SRCCOPY = &HCC0020 Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _ ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _ ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _ ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _ ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Sub Form_Load() With Picture1 .AutoSize = True .Visible = False .AutoRedraw = True .BorderStyle = 0 End With With Picture2 .AutoSize = True .Visible = False .AutoRedraw = True .BorderStyle = 0 End With With Picture3 .Width = Picture1.Width .Height = Picture1.Height .Visible = False .AutoRedraw = True .BorderStyle = 0 End With With Picture4 .Width = Picture1.Width .Height = Picture1.Height .AutoRedraw = True .BorderStyle = 0 End With End Sub Private Sub Timer1_Timer() Picture3.Cls If Cos(dAngle * PI / 180) >= 0 Then Call StretchBlt(Picture3.hdc, (Picture1.Width - Abs(Cos(dAngle * PI / 180) * _ Picture1.Width)) / (2 * Screen.TwipsPerPixelX), 0, Abs(Cos(dAngle * PI / 180) * _ Picture1.Width) / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, _ Picture1.hdc, 0, 0, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / _ Screen.TwipsPerPixelY, SRCCOPY) ElseIf Cos(dAngle * PI / 180) < 0 Then Call StretchBlt(Picture3.hdc, (Picture2.Width - Abs(Cos(dAngle * PI / 180) * _ Picture2.Width)) / (2 * Screen.TwipsPerPixelX), 0, Abs(Cos(dAngle * PI / 180) * _ Picture2.Width) / Screen.TwipsPerPixelX, Picture2.Height / Screen.TwipsPerPixelY, _ Picture2.hdc, 0, 0, Picture2.Width / Screen.TwipsPerPixelX, Picture2.Height / _ Screen.TwipsPerPixelY, SRCCOPY) End If Call BitBlt(Picture4.hdc, 0, 0, Picture3.Width / Screen.TwipsPerPixelX, Picture3.Height / _ Screen.TwipsPerPixelY, Picture3.hdc, 0, 0, SRCCOPY) Picture4.Refresh dAngle = dAngle + 360 / NUM_TURNS dAngle = dAngle Mod 360 End Sub |
Related posts:
- How to Make Scrolling Credits
- How to stretch Picture Box
- How to select portion of Picture and paste it to Picture Box
- How to replace a Color with another Color in Picture Box
- How to Copy the contents of a Picture Box into Clipboard
- How to get Dimensions of an image
- How to stretch picture in a picture box
- How to Draw Rainbow Text in Picture Box
- How to center a picture in Picture box Control
- How to Keep a form always on top even when you click on another window.