daDom
Erfahrenes Mitglied
Also, ich habe folgendes Problem:
Ich brauche einen Code, mit dem ich Grafiken frei rotieren lassen kann...
Habe dieses hier gefunden: http://www.flomix.de/download/foxcbmp_src.zip
Den Code-Teil der Rotieren-Funktion habe ich heraus kopiert und so wie er ist - unverändert - klappt es auch alles...
In meinem Programm schiebe ich Grafiken(Inhalt einer Picbox) in einer weiteren Picbox herum.
In dem vorgegebenen Code sind ebenfalls 2 Picbox'en aber das jeweilige Bild dreht sich immer nur in der Mitte der größeren Picbox.
Ind dieser Funktion kommt des öfteren "picRotate.hdc" oder "picRotate.Image.Handle" vor. Was bedeutet das?
FoxRotate picRotate.hdc, picRotate.ScaleWidth \ 2, picRotate.ScaleHeight \ 2, picRot.hdc, picRot.Image.Handle, &HFF00FF, HScroll3 / 10, chkRotMask + chkRotSmooth * 2
Kann ich durch den Teil (oben) irgendwie die Position des sich drehenden Objektes verändern?
#############################################################
#############################################################
Hier der Code-Teil, der die Rotation berechnet:
Code in der "VB-only.bas":
Public Function FoxRotate(ByVal DstDC As Long, ByVal DstX As Long, ByVal DstY As Long, ByVal SrcDC As Long, ByVal SrcBmp As Long, ByVal TransColor As Long, ByVal Angle As Double, Optional ByVal Flags As Long) As Long
Dim TmpDC As Long, TmpBmp As Long, OldObject As Long
Dim BitCount As Long, BitCount2 As Long, LineWidth As Long, LineWidth2 As Long
Dim retVal As Long
Dim Width As Long, Height As Long, NewSize As Long
Dim H As Long, B As Long, F As Long, D As Long, I As Long
Dim dx1 As Double, dy1 As Double
Dim TransR As Byte, TransG As Byte, TransB As Byte
Dim TempAlpha As Byte
Dim Info As BITMAPINFO, Info2 As BITMAPINFO
Dim SrcBits() As Byte, TmpBits() As Byte
TransR = TransColor And &HFF
TransG = (TransColor And &HFF00&) / 255
TransB = (TransColor And &HFF0000) / 65536
Info.bmiHeader.biSize = Len(Info.bmiHeader)
Info2.bmiHeader.biSize = Len(Info2.bmiHeader)
retVal = GetDIBits(SrcDC, SrcBmp, 0, 0, ByVal 0, Info, 0)
If retVal = 0 Then Exit Function
TmpDC = CreateCompatibleDC(SrcDC)
Width = Info.bmiHeader.biWidth
Height = Info.bmiHeader.biHeight
NewSize = Math.Sqr(Width ^ 2 + Height ^ 2) + 2
TmpBmp = CreateCompatibleBitmap(SrcDC, NewSize, NewSize)
If TmpBmp Then
OldObject = SelectObject(TmpDC, TmpBmp)
BitBlt TmpDC, 0, 0, NewSize, NewSize, DstDC, DstX - NewSize / 2, DstY - NewSize / 2, vbSrcCopy
Info.bmiHeader.biBitCount = 24
Info.bmiHeader.biCompression = 0
Info2.bmiHeader.biBitCount = 24
Info2.bmiHeader.biCompression = 0
Info2.bmiHeader.biPlanes = 1
Info2.bmiHeader.biHeight = NewSize
Info2.bmiHeader.biWidth = NewSize
LineWidth = Width * 3
If (LineWidth Mod 4) Then LineWidth = LineWidth + 4 - (LineWidth Mod 4)
BitCount = LineWidth * Height
LineWidth2 = NewSize * 3
If (LineWidth2 Mod 4) Then LineWidth2 = LineWidth2 + 4 - (LineWidth2 Mod 4)
BitCount2 = LineWidth2 * NewSize
ReDim SrcBits(BitCount - 1)
ReDim TmpBits(BitCount2 - 1)
GetDIBits SrcDC, SrcBmp, 0, Height, SrcBits(0), Info, 0
GetDIBits TmpDC, TmpBmp, 0, NewSize, TmpBits(0), Info2, 0
Dim CurOffset As Long
Dim NewX As Double, NewY As Double
Dim Xmm As Long, Ymm As Long
Dim I1 As Long
Dim v1 As Boolean
dx1 = Cos(Angle * PIDEG)
dy1 = Sin(Angle * PIDEG)
For H = 0 To NewSize - 1
CurOffset = LineWidth2 * H
For B = 0 To NewSize - 1
F = CurOffset + 3 * B
NewX = Width / 2 + (B - NewSize / 2) * dx1 - (H - NewSize / 2) * dy1
NewY = Height / 2 + (B - NewSize / 2) * dy1 + (H - NewSize / 2) * dx1
Xmm = Int(NewX + 0.5)
Ymm = Int(NewY + 0.5)
If (Xmm >= 0) And (Xmm < Width) And (Ymm >= 0) And (Ymm < Height) Then
v1 = True
I1 = LineWidth * Ymm + 3 * Xmm
If Flags And &H1 Then
v1 = Not (SrcBits(I1 + 2) = TransR And SrcBits(I1 + 1) = TransG And SrcBits(I1) = TransB)
End If
If v1 Then For D = 0 To 2: TmpBits(F + D) = SrcBits(I1 + D): Next D
End If
Next B
Next H
SetDIBitsToDevice DstDC, DstX - NewSize / 2, DstY - NewSize / 2, NewSize, NewSize, 0, 0, 0, NewSize, TmpBits(0), Info2, 0
Erase SrcBits
Erase TmpBits
DeleteObject SelectObject(TmpDC, OldObject)
End If
DeleteDC TmpDC
End Function
Ich brauche einen Code, mit dem ich Grafiken frei rotieren lassen kann...
Habe dieses hier gefunden: http://www.flomix.de/download/foxcbmp_src.zip
Den Code-Teil der Rotieren-Funktion habe ich heraus kopiert und so wie er ist - unverändert - klappt es auch alles...
In meinem Programm schiebe ich Grafiken(Inhalt einer Picbox) in einer weiteren Picbox herum.
In dem vorgegebenen Code sind ebenfalls 2 Picbox'en aber das jeweilige Bild dreht sich immer nur in der Mitte der größeren Picbox.
Ind dieser Funktion kommt des öfteren "picRotate.hdc" oder "picRotate.Image.Handle" vor. Was bedeutet das?
FoxRotate picRotate.hdc, picRotate.ScaleWidth \ 2, picRotate.ScaleHeight \ 2, picRot.hdc, picRot.Image.Handle, &HFF00FF, HScroll3 / 10, chkRotMask + chkRotSmooth * 2
Kann ich durch den Teil (oben) irgendwie die Position des sich drehenden Objektes verändern?
#############################################################
#############################################################
Hier der Code-Teil, der die Rotation berechnet:
Code in der "VB-only.bas":
Public Function FoxRotate(ByVal DstDC As Long, ByVal DstX As Long, ByVal DstY As Long, ByVal SrcDC As Long, ByVal SrcBmp As Long, ByVal TransColor As Long, ByVal Angle As Double, Optional ByVal Flags As Long) As Long
Dim TmpDC As Long, TmpBmp As Long, OldObject As Long
Dim BitCount As Long, BitCount2 As Long, LineWidth As Long, LineWidth2 As Long
Dim retVal As Long
Dim Width As Long, Height As Long, NewSize As Long
Dim H As Long, B As Long, F As Long, D As Long, I As Long
Dim dx1 As Double, dy1 As Double
Dim TransR As Byte, TransG As Byte, TransB As Byte
Dim TempAlpha As Byte
Dim Info As BITMAPINFO, Info2 As BITMAPINFO
Dim SrcBits() As Byte, TmpBits() As Byte
TransR = TransColor And &HFF
TransG = (TransColor And &HFF00&) / 255
TransB = (TransColor And &HFF0000) / 65536
Info.bmiHeader.biSize = Len(Info.bmiHeader)
Info2.bmiHeader.biSize = Len(Info2.bmiHeader)
retVal = GetDIBits(SrcDC, SrcBmp, 0, 0, ByVal 0, Info, 0)
If retVal = 0 Then Exit Function
TmpDC = CreateCompatibleDC(SrcDC)
Width = Info.bmiHeader.biWidth
Height = Info.bmiHeader.biHeight
NewSize = Math.Sqr(Width ^ 2 + Height ^ 2) + 2
TmpBmp = CreateCompatibleBitmap(SrcDC, NewSize, NewSize)
If TmpBmp Then
OldObject = SelectObject(TmpDC, TmpBmp)
BitBlt TmpDC, 0, 0, NewSize, NewSize, DstDC, DstX - NewSize / 2, DstY - NewSize / 2, vbSrcCopy
Info.bmiHeader.biBitCount = 24
Info.bmiHeader.biCompression = 0
Info2.bmiHeader.biBitCount = 24
Info2.bmiHeader.biCompression = 0
Info2.bmiHeader.biPlanes = 1
Info2.bmiHeader.biHeight = NewSize
Info2.bmiHeader.biWidth = NewSize
LineWidth = Width * 3
If (LineWidth Mod 4) Then LineWidth = LineWidth + 4 - (LineWidth Mod 4)
BitCount = LineWidth * Height
LineWidth2 = NewSize * 3
If (LineWidth2 Mod 4) Then LineWidth2 = LineWidth2 + 4 - (LineWidth2 Mod 4)
BitCount2 = LineWidth2 * NewSize
ReDim SrcBits(BitCount - 1)
ReDim TmpBits(BitCount2 - 1)
GetDIBits SrcDC, SrcBmp, 0, Height, SrcBits(0), Info, 0
GetDIBits TmpDC, TmpBmp, 0, NewSize, TmpBits(0), Info2, 0
Dim CurOffset As Long
Dim NewX As Double, NewY As Double
Dim Xmm As Long, Ymm As Long
Dim I1 As Long
Dim v1 As Boolean
dx1 = Cos(Angle * PIDEG)
dy1 = Sin(Angle * PIDEG)
For H = 0 To NewSize - 1
CurOffset = LineWidth2 * H
For B = 0 To NewSize - 1
F = CurOffset + 3 * B
NewX = Width / 2 + (B - NewSize / 2) * dx1 - (H - NewSize / 2) * dy1
NewY = Height / 2 + (B - NewSize / 2) * dy1 + (H - NewSize / 2) * dx1
Xmm = Int(NewX + 0.5)
Ymm = Int(NewY + 0.5)
If (Xmm >= 0) And (Xmm < Width) And (Ymm >= 0) And (Ymm < Height) Then
v1 = True
I1 = LineWidth * Ymm + 3 * Xmm
If Flags And &H1 Then
v1 = Not (SrcBits(I1 + 2) = TransR And SrcBits(I1 + 1) = TransG And SrcBits(I1) = TransB)
End If
If v1 Then For D = 0 To 2: TmpBits(F + D) = SrcBits(I1 + D): Next D
End If
Next B
Next H
SetDIBitsToDevice DstDC, DstX - NewSize / 2, DstY - NewSize / 2, NewSize, NewSize, 0, 0, 0, NewSize, TmpBits(0), Info2, 0
Erase SrcBits
Erase TmpBits
DeleteObject SelectObject(TmpDC, OldObject)
End If
DeleteDC TmpDC
End Function