|
-
Oct 10th, 2012, 09:32 PM
#1
Thread Starter
New Member
[VB6] Rotate Image
Hi Guys,
Do you have any idea to rotate image from VB6.0 (just the way windows photo viewer did).
I made an image viewer (zoom in, zoom out) to compare image, the problem is I can't rotate the image.
Kindly advice..
Thanks,
Jefri
-
Oct 11th, 2012, 06:36 AM
#2
Re: [VB6] Rotate Image
Found on a german VB-Website: http://www.vbarchiv.net/tipps/details.php?id=938
Code:
Private Const pi = 3.14159265359
Public Sub RotatePicture(ByVal picSource As PictureBox, ByVal picDest As PictureBox, Optional ByVal Angle As Long = 0)
' cp0 - cp3 = Color of single Pixel
Dim cp0 As Long, cp1 As Long
Dim cp2 As Long, cp3 As Long
' Picture-Dimensions
Dim w1 As Long, h1 As Long
Dim w2 As Long, h2 As Long
Dim p1x As Double, p1y As Double
Dim p2x As Double, p2y As Double
Dim n As Double, r As Double, a As Double
picSource.AutoSize = True
picSource.Visible = False
picSource.AutoRedraw = True
picDest.AutoRedraw = True
picSource.ScaleMode = vbPixels
picDest.ScaleMode = vbPixels
Set picDest.Picture = Nothing
picDest.Cls
w1 = picSource.ScaleWidth \ 2
h1 = picSource.ScaleHeight \ 2
w2 = picDest.ScaleWidth \ 2
h2 = picDest.ScaleHeight \ 2
' Angle = pi * (Angle / 180)
If w2 < h2 Then n = h2 Else n = w2
n = n - 1
For p2x = 0 To n
For p2y = 0 To n
' Calculate Position
If p2x = 0 Then a = pi / 2 Else a = Atn(p2y / p2x)
r = Sqr(p2x * p2x + p2y * p2y)
p1x = r * Cos(a + (pi * Angle / 180))
p1y = r * Sin(a + (pi * Angle / 180))
cp0 = picSource.Point(w1 + p1x, h1 + p1y)
cp1 = picSource.Point(w1 - p1x, h1 - p1y)
cp2 = picSource.Point(w1 + p1y, h1 - p1x)
cp3 = picSource.Point(w1 - p1y, h1 + p1x)
If cp0 <> -1 Then picDest.PSet (w2 + p2x, h2 + p2y), cp0
If cp1 <> -1 Then picDest.PSet (w2 - p2x, h2 - p2y), cp1
If cp2 <> -1 Then picDest.PSet (w2 + p2y, h2 - p2x), cp2
If cp3 <> -1 Then picDest.PSet (w2 - p2y, h2 + p2x), cp3
Next p2y
Next p2x
Set picDest.Picture = picDest.Image
End Sub
Not tested!
Last edited by Zvoni; Oct 11th, 2012 at 06:48 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
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
|