Hallo Dany,
hierzu brauchst Du folgenden Code:
<code><font color=green>' zunächst die benötigten API-Deklarationen</font>
Private Declare Function SetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, _
ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, _
ByVal y As Long) As Long
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
Const SRCCOPY = &HCC0020
Const Pi = 3.14159265359
<font color=green>' PictureBox drehen</font>
Sub RotatePicture(picSource As PictureBox, _
picDest As PictureBox, ByVal Winkel As Single)
<font color=green>' Drehen eines Bildes einer PictureBox
' und Anzeige des Bildes in einer zweiten PictureBox</font>
<font color=green>' cp0 - cp3 = Farbe eines einzelnen Pixels</font>
Dim cp0 As Long, cp1 As Long
Dim cp2 As Long, cp3 As Long
<font color=green>' Pixel-Koordinaten</font>
Dim c1x As Long, c1y As Long
Dim c2x As Long, c2y As Long
<font color=green>' Geräte-Kontext der beiden PictureBoxen</font>
Dim p1hDC As Long
Dim p2hDC As Long
Dim a As Single
Dim p1x As Long, p1y As Long
Dim p2x As Long, p2y As Long
Dim n As Long, r As Long
c1x = picSource.ScaleWidth 2
c1y = picSource.ScaleHeight 2
c2x = picDest.ScaleWidth 2
c2y = picDest.ScaleHeight 2
If c2x < c2y Then n = c2y Else n = c2x
n = n - 1
p1hDC = picSource.hdc
p2hDC = picDest.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(p2x * p2x + p2y * p2y)
p1x = r * Cos(a + Winkel)
p1y = r * Sin(a + Winkel)
cp0 = GetPixel(p1hDC, c1x + p1x, c1y + p1y)
cp1 = GetPixel(p1hDC, c1x - p1x, c1y - p1y)
cp2 = GetPixel(p1hDC, c1x + p1y, c1y - p1x)
cp3 = GetPixel(p1hDC, c1x - p1y, c1y + p1x)
If cp0 <> -1 Then SetPixel p2hDC, c2x + p2x, c2y + p2y, cp0
If cp1 <> -1 Then SetPixel p2hDC, c2x - p2x, c2y - p2y, cp1
If cp2 <> -1 Then SetPixel p2hDC, c2x + p2y, c2y - p2x, cp2
If cp3 <> -1 Then SetPixel p2hDC, c2x - p2y, c2y + p2x, cp3
Next p2y
Next p2x
End Sub</code> Die Vorgehensweise ist folgende:
Du benötigst neben der Quell-PictureBox noch eine zweite - die Ziel-PictureBox, welche das gedrehte Bild enthalten soll.
Der Aufruf ist ganz einfach:
<code>RotatePicture Picture1, Picture2, PI / 2</code> Viel Spass damit!
Cu
Dieter |