Visual Basic - Solo para Genios

Life is soft - evento anual de software empresarial
 
Vista:

Solo para Genios

Publicado por Garry (3 intervenciones) el 28/07/2003 02:30:02
Hola amigos, tengo un pequeño problema. Como podría girar una imagen cargado en un PictureBox, tantos grados como yo kiera??. Gracias por cualquier ayuda que se aporte
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Solo para Genios I

Publicado por Carlos (55 intervenciones) el 28/07/2003 03:16:57
'Agrega tres botones y dos picturebox. Carga un bitmap en picture1 en modo de diseño. Establece ambos picturebox al mismo tamaño. Las rutinas se ejecutan 3 vez más rápidamente que las que se encuentran en "Microsoft's Knowledge Base"

Private Const SRCCOPY = &HCC0020
Private Const Pi = 3.14159265359
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, _
ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, _
ByVal X As Integer, ByVal Y As Integer) As Long
Private 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&)

Sub Form_Load()
Picture1.ScaleMode = 3 'Píxels
Picture2.ScaleMode = 3
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Solo para Genios II

Publicado por Carlos (55 intervenciones) el 28/07/2003 03:17:58
Sub Command1_Click()
'giro horizontal
Picture2.Cls
px% = Picture1.ScaleWidth
py% = Picture1.ScaleHeight
retval% = StretchBlt(Picture2.hDC, px%, 0, -px%, py%, Picture1.hDC, _
0, 0, px%, py%, SRCCOPY)
End Sub

Sub Command2_Click()
'giro horizontal
Picture2.Cls
px% = Picture1.ScaleWidth
py% = Picture1.ScaleHeight
retval% = StretchBlt(Picture2.hDC, 0, py%, px%, -py%, Picture1.hDC, _
0, 0, px%, py%, SRCCOPY)
End Sub

Sub Command3_Click()
'girar, por ejemplo, 45 grados
Picture2.Cls
Call bmp_rotate(Picture1, Picture2, Pi / 4)
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Solo para Genios III

Publicado por Carlos (55 intervenciones) el 28/07/2003 03:19:15
Sub bmp_rotate(pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
' bmp_rotate(pic1, pic2, theta)
' Gira la imagen en un picturebox.
' pic1 es el picturebox con la imagen a girar
' pic2 es el picturebox que recibirá la imagen girada
' theta es el ángulo de rotación
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

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
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Solo para Genios y IV

Publicado por Carlos (55 intervenciones) el 28/07/2003 03:20:37
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

'Sólo debes unir estas 4 notas y tendrás el código

'Copiado y traducido de http://www.geocities.com/SiliconValley/hills/4377/surse7.htm

'Buscar un poquito en Google debe ser de genios, así que SOY UN GENIO.

Un saludo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar