Вот нашёл пример, как вертеть картинку. Довольно быстрый пример, но не работает в ХР. У меня выдаётся ошибка "Переполнение". Странно, но hDC в ХР обычно 939594146 или -14467785445, что, по-моему, многоватоа, а в 98 89975 или что-то в этом духе. Не подскажите, в чём тут дело????????? Вот пример: Нужно 2 пикча Pic1 и Pic2 >-------------------------------------------------------< Declare Function SetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Long) As Long Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Long 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&) Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWid As Integer, ByVal nHt As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer Const SRCCOPY = &HCC0020 Public Const Pi = 3.14159265359 Public Sub BmpRotate(pic1 As PictureBox, pic2 As PictureBox, ByVal theta!) ' Поворот изображениея в picture box. ' pic1 - picture box с картинкой, которую будем вращать. ' pic2 - picture box, получающий результирующую картинку ' theta - угол вращения ' 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 pic1.ScaleMode = 3 pic2.ScaleMode = 3 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 Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyLeft Then gradus = gradus + 3.49065850398889E-02: Me.Cls: Print gradus / 1.74532925199444E+31 If KeyCode = vbKeyRight Then gradus = gradus - 3.49065850398889E-02: Me.Cls: Print gradus / 1.74532925199444E+31 If KeyCode = vbKeyUp Then pic2.Top = pic2.Top + 5 BmpRotate pic1, pic2, gradus End Sub Private Sub Form_Load() gradus = 0 End Sub
Ответить
|