elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


  Mostrar Mensajes
Páginas: 1 ... 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 [127] 128 129 130 131 132 133 134 135 136 137
1261  Programación / Programación Visual Basic / Re: [Source] Funcion para marcar contornos de una imagen. en: 6 Diciembre 2010, 19:15 pm
HOLA!!!

Karcrack: Listo ahi esta la imagen :P

GRACIAS POR LEER!!!
1262  Programación / Programación Visual Basic / [Source] Funciones para marcar contornos de una imagen y marcar piel. en: 6 Diciembre 2010, 14:26 pm
HOLA!!!

EFECTO:


Gracias a LEANDRO A pude armar una funcion que convierte una imagen cualquiera a una imagen en ByN puro sin escala de grises marcando solamente los contornos de las cosas.

AGREGADO: funcion para pintar las zonas que son piel.



Hay una variable "Tolerance" esa la regulan para que sea mas o menos estricto con la deteccion de bordes.

Bueno aca el codigo (Modulo):
Repito GRACIAS LEA!
Código
  1. Option Explicit
  2. Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, pBitmapInfo As BITMAPINFO24, ByVal un As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  3. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
  4. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
  5. Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
  6. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
  7. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
  8. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  9. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
  10. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  11. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
  12.  
  13. Private Type RGBQUAD
  14.    rgbBlue As Byte
  15.    rgbGreen As Byte
  16.    rgbRed As Byte
  17.    rgbReserved As Byte
  18. End Type
  19.  
  20. Private Type BITMAPINFOHEADER
  21.    biSize As Long
  22.    biWidth As Long
  23.    biHeight As Long
  24.    biPlanes As Integer
  25.    biBitCount As Integer
  26.    biCompression As Long
  27.    biSizeImage As Long
  28.    biXPelsPerMeter As Long
  29.    biYPelsPerMeter As Long
  30.    biClrUsed As Long
  31.    biClrImportant As Long
  32. End Type
  33.  
  34. Private Type BITMAPINFO24
  35.    bmiHeader As BITMAPINFOHEADER
  36.    bmiColors() As RGBQUAD
  37. End Type
  38.  
  39. Private Type SAFEARRAYBOUND
  40.    cElements As Long
  41.    lLbound As Long
  42. End Type
  43.  
  44. Private Type SAFEARRAY2D
  45.    cDims As Integer
  46.    fFeatures As Integer
  47.    cbElements As Long
  48.    cLocks As Long
  49.    pvData As Long
  50.    Bounds(0 To 1) As SAFEARRAYBOUND
  51. End Type
  52.  
  53.  
  54. Private Const DIB_RGB_COLORS = 0
  55. Private Const BI_RGB = 0&
  56.  
  57.  
  58. Public Sub BuscarContornos(Pic As PictureBox)
  59.    Dim BytesPerLine As Long
  60.    Dim WinDC As Long
  61.    Dim TmpDC As Long
  62.    Dim hBmp As Long
  63.    Dim OldBmp As Long
  64.    Dim Addrs As Long
  65.    Dim x As Long
  66.    Dim y As Long
  67.    Dim lpBits() As Byte
  68.    Dim M_BitmapInfo As BITMAPINFO24
  69.    Dim SA As SAFEARRAY2D
  70.    Dim R As Byte, G As Byte, B As Byte, BYN As Byte, Tolerance As Byte
  71.    Dim ZERO As Integer
  72.    Dim tmp1 As Integer, tmp2 As Integer, tmp3 As Integer
  73.    Tolerance = 20
  74.    ZERO = 0
  75.    BytesPerLine = ScanAlign(Pic.ScaleWidth * 3)
  76.  
  77.    With M_BitmapInfo.bmiHeader
  78.        .biSize = Len(M_BitmapInfo.bmiHeader)
  79.        .biWidth = Pic.ScaleWidth
  80.        .biHeight = Pic.ScaleHeight
  81.        .biPlanes = 1
  82.        .biBitCount = 24
  83.        .biCompression = BI_RGB
  84.        .biSizeImage = BytesPerLine * Pic.ScaleHeight
  85.    End With
  86.  
  87.    WinDC = GetDC(0)
  88.    TmpDC = CreateCompatibleDC(WinDC)
  89.    hBmp = CreateDIBSection(WinDC, M_BitmapInfo, DIB_RGB_COLORS, Addrs, 0, 0)
  90.  
  91.    Call ReleaseDC(0, WinDC)
  92.  
  93.    With SA
  94.        .cbElements = 1
  95.        .cDims = 2
  96.        .Bounds(0).lLbound = 0
  97.        .Bounds(0).cElements = Pic.ScaleHeight
  98.        .Bounds(1).lLbound = 0
  99.        .Bounds(1).cElements = BytesPerLine
  100.        .pvData = Addrs
  101.    End With
  102.  
  103.    CopyMemory ByVal VarPtrArray(lpBits), VarPtr(SA), 4
  104.  
  105.    OldBmp = SelectObject(TmpDC, hBmp)
  106.  
  107.    Call BitBlt(TmpDC, 0, 0, Pic.ScaleWidth, Pic.ScaleHeight, Pic.hDC, 0, 0, vbSrcCopy)
  108.  
  109.    For y = 0 To Pic.ScaleHeight - 1
  110.        For x = 0 To (Pic.ScaleWidth * 3) - 1 Step 3
  111.  
  112.            B = lpBits(x + 2, y)
  113.            G = lpBits(x + 1, y)
  114.            R = lpBits(x, y)
  115.  
  116.  
  117.            'ZERO ES PARA QUE NO HAGA DESBORDAMIENTO
  118.            BYN = Int((ZERO + R + G + B) / 3)
  119.  
  120.            'DIBUJA EN BLANCO Y NEGRO
  121.  
  122.            lpBits(x, y) = BYN
  123.            lpBits(x + 1, y) = BYN
  124.            lpBits(x + 2, y) = BYN
  125.            If x <> 0 And y <> 0 Then
  126.            tmp1 = lpBits(x - 1, y - 1)
  127.            tmp2 = lpBits(x - 1, y)
  128.            tmp3 = lpBits(x, y - 1)
  129.            If Abs(tmp2 - tmp1) > Tolerance Or Abs(tmp3 - tmp1) > Tolerance Then
  130.                lpBits(x - 1, y - 1) = 0
  131.                lpBits(x - 2, y - 1) = 0
  132.                lpBits(x - 3, y - 1) = 0
  133.            Else
  134.                'PINTA DE NEGRO EL PIXEL POR QUE AHI HAY UN BORDE
  135.                lpBits(x - 1, y - 1) = 255
  136.                lpBits(x - 2, y - 1) = 255
  137.                lpBits(x - 3, y - 1) = 255
  138.            End If
  139.            End If
  140.        Next x
  141.    Next y
  142.  
  143.    CopyMemory ByVal VarPtrArray(lpBits), 0&, 4
  144.    Call BitBlt(Pic.hDC, 0, 0, Pic.ScaleWidth, Pic.ScaleHeight, TmpDC, 0, 0, vbSrcCopy)
  145.    Call DeleteObject(SelectObject(TmpDC, OldBmp))
  146.    Call DeleteDC(TmpDC)
  147.  
  148.  
  149.  
  150. End Sub
  151.  
  152. Public Sub BuscarPiel(Pic As PictureBox)
  153.    Dim BytesPerLine As Long
  154.    Dim WinDC As Long
  155.    Dim TmpDC As Long
  156.    Dim hBmp As Long
  157.    Dim OldBmp As Long
  158.    Dim Addrs As Long
  159.    Dim x As Long
  160.    Dim y As Long
  161.    Dim lpBits() As Byte
  162.    Dim M_BitmapInfo As BITMAPINFO24
  163.    Dim SA As SAFEARRAY2D
  164.    Dim R As Byte, G As Byte, B As Byte, BYN As Byte, Tolerance As Byte
  165.    Dim ZERO As Integer
  166.    Dim tmp1 As Integer, tmp2 As Integer, tmp3 As Integer
  167.    Tolerance = 20
  168.    ZERO = 0
  169.    BytesPerLine = ScanAlign(Pic.ScaleWidth * 3)
  170.  
  171.    With M_BitmapInfo.bmiHeader
  172.        .biSize = Len(M_BitmapInfo.bmiHeader)
  173.        .biWidth = Pic.ScaleWidth
  174.        .biHeight = Pic.ScaleHeight
  175.        .biPlanes = 1
  176.        .biBitCount = 24
  177.        .biCompression = BI_RGB
  178.        .biSizeImage = BytesPerLine * Pic.ScaleHeight
  179.    End With
  180.  
  181.    WinDC = GetDC(0)
  182.    TmpDC = CreateCompatibleDC(WinDC)
  183.    hBmp = CreateDIBSection(WinDC, M_BitmapInfo, DIB_RGB_COLORS, Addrs, 0, 0)
  184.  
  185.    Call ReleaseDC(0, WinDC)
  186.  
  187.    With SA
  188.        .cbElements = 1
  189.        .cDims = 2
  190.        .Bounds(0).lLbound = 0
  191.        .Bounds(0).cElements = Pic.ScaleHeight
  192.        .Bounds(1).lLbound = 0
  193.        .Bounds(1).cElements = BytesPerLine
  194.        .pvData = Addrs
  195.    End With
  196.  
  197.    CopyMemory ByVal VarPtrArray(lpBits), VarPtr(SA), 4
  198.  
  199.    OldBmp = SelectObject(TmpDC, hBmp)
  200.  
  201.    Call BitBlt(TmpDC, 0, 0, Pic.ScaleWidth, Pic.ScaleHeight, Pic.hDC, 0, 0, vbSrcCopy)
  202.  
  203.    For y = 0 To Pic.ScaleHeight - 1
  204.        For x = 0 To (Pic.ScaleWidth * 3) - 1 Step 3
  205.  
  206.            R = lpBits(x + 2, y)
  207.            G = lpBits(x + 1, y)
  208.            B = lpBits(x, y)
  209.  
  210.  
  211.            'ZERO ES PARA QUE NO HAGA DESBORDAMIENTO
  212.            BYN = Int((ZERO + R + G + B) / 3)
  213.  
  214.            'DIBUJA EN BLANCO Y NEGRO
  215.            If R > 168 And G > 134 And B > 94 And R < 250 And G < 235 And B < 215 Then
  216.            ' LOS PROXIMOS 3 VALORES ESPECIFICAN EL COLOR CON EL QUE SE VA A PINTAR
  217.            lpBits(x, y) = 0
  218.            lpBits(x + 1, y) = 255
  219.            lpBits(x + 2, y) = 255
  220.            Else
  221.            lpBits(x, y) = 0 ' BYN
  222.            lpBits(x + 1, y) = 0 'BYN
  223.            lpBits(x + 2, y) = 0 'BYN
  224.            End If
  225.        Next x
  226.    Next y
  227.  
  228.    CopyMemory ByVal VarPtrArray(lpBits), 0&, 4
  229.    Call BitBlt(Pic.hDC, 0, 0, Pic.ScaleWidth, Pic.ScaleHeight, TmpDC, 0, 0, vbSrcCopy)
  230.    Call DeleteObject(SelectObject(TmpDC, OldBmp))
  231.    Call DeleteDC(TmpDC)
  232.  
  233.  
  234.  
  235. End Sub
  236.  
  237. Private Function ScanAlign(WidthBmp As Long) As Long
  238.    ScanAlign = (WidthBmp + 3) And &HFFFFFFFC
  239. End Function
  240.  
  241.  

Para llamar la funcion:
Código
  1. Private Sub Command1_Click()
  2.    'ESTO PARA CONTORNOS
  3.    BuscarContornos PicTratamiento
  4.    'ESTO PARA PIEL
  5.    BuscarPiel PicTratamiento
  6.    PicTratamiento.Refresh
  7. End Sub
  8.  
  9. Private Sub Form_Load()
  10.    PicTratamiento.AutoRedraw = True
  11.    PicTratamiento.ScaleMode = vbPixels
  12. End Sub

P.D: El de la foto soy yo asi que no puteen.
GRACIAS POR LEER!!!
1263  Programación / Programación Visual Basic / Re: [Ayuda]Reconocer contornos Picturebox en: 6 Diciembre 2010, 11:48 am
HOLA!!!

 ;-) ;-) ;-) ;-) ;-)

Gracias LEA!!!
Me ayudaste un monton, me sirve mucho gracias :D

GRACIAS POR LEER!!!
1264  Programación / Programación Visual Basic / [Ayuda]Reconocer contornos Picturebox en: 3 Diciembre 2010, 16:14 pm
HOLA!!!

Como andan?, hoy tengo una duda, estoy intentando encontrar los contornos de los objetos de una foto(en un picturebox) logre armar algo buscando en google, pero es  muy inpresiso.

La imagen se trata en un Picturebox chico asi no tarda mucho, sino se come el procesador.

Si encuentran algo o ven algo en mi codigo avisenme.

Bueno, les dejo mi codigo para que lo vean.
Esto va en un modulo y en el Form1 ponen un picturebox con una imagen (chica :P) hacen un call a la funcion y listo.
Código
  1. Public color As Long
  2. Public ElR As Byte
  3. Public ElG As Byte
  4. Public ElB As Byte
  5. Dim P12 As Integer, P21 As Integer, P22 As Integer
  6.  
  7. Public Sub RGBdelPixel(x As Integer, y As Integer)
  8.   color = Form1.PicTratamiento.Point(x - 1, y)
  9.   ElB = (color \ 65536) And &HFF
  10.   ElG = (color \ 256) And &HFF
  11.   ElR = color And &HFF
  12.   P12 = (70! * ElR + 150! * ElG + 29! * ElB) / 255
  13.   color = Form1.PicTratamiento.Point(x, y - 1)
  14.   ElB = (color \ 65536) And &HFF
  15.   ElG = (color \ 256) And &HFF
  16.   ElR = color And &HFF
  17.   P21 = (70! * ElR + 150! * ElG + 29! * ElB) / 255
  18.   color = Form1.PicTratamiento.Point(x, y)
  19.   ElB = (color \ 65536) And &HFF
  20.   ElG = (color \ 256) And &HFF
  21.   ElR = color And &HFF
  22.   P22 = (70! * ElR + 150! * ElG + 29! * ElB) / 255
  23. End Sub
  24.  
  25. Public Sub Contornos()
  26. Dim AltUrA As Integer, lArgO As Integer, color As Integer
  27. Dim i As Integer, j As Integer
  28. Form1.PicTratamiento.ScaleMode = 3
  29. AltUrA = Form1.PicTratamiento.ScaleHeight
  30. lArgO = Form1.PicTratamiento.ScaleWidth
  31. tolerancia = 100
  32.  
  33. For i = 1 To lArgO - 1
  34.    For j = 1 To AltUrA - 1
  35.        RGBdelPixel i, j
  36.        If Abs(P12 - P22) > tolerancia Or Abs(P21 - P22) > tolerancia Then
  37.            Form1.PicTratamiento.PSet (i, j) ', RGB(P22, P22, P22)
  38.        Else
  39.            Form1.PicTratamiento.PSet (i, j), vbWhite
  40.        End If
  41. Next
  42. Next
  43. Form1.PicTratamiento.ScaleMode = 1
  44. End Sub

GRACIAS POR LEER!!!
1265  Programación / Programación General / Re: [Ehn-Dev 2010] - Votaciones!!! en: 3 Diciembre 2010, 14:24 pm
HOLA!!!

MUY BUENOS PROGRAMAS, ME ENCANTARON.

MI PODIO:


                            FrogCheat 
          DLLGenius|        1        |
         |        2                          |Notas por Red 
         |                                                 3          |

GRACIAS POR LEER!!!
1266  Programación / Programación Visual Basic / Re: Administrar el Tiempo en: 1 Diciembre 2010, 18:00 pm
HOLA!!!

Usa el DOS, el comando "shutdown"

Si no queres leer tanto usa "shutdown -i" en la ventana ejecutar y te carga la GUI

Uso: shutdown [-l | -s | -r | -a] [-f] [-m \\equipo] [-t xx] [-c "comentario"] [
-d up:xx:yy]

        Sin argumentos  Mostrar este mensaje (igual a -?)
      -i                Mostrar interfaz GUI, debe ser la primera opción
        -l                      Cerrar sesión (no se puede usar con la opción -m
)
        -s                      Apagar el equipo
        -r                      Apagar y reiniciar el equipo
        -a                      Anular el apagado de equipo
        -m \\equipo             Equipo que se apagará/reiniciará/anulara
        -t xx                   Establecer el tiempo de espera de apagado en xx
                               segundos
        -c "comentario"         Comentario de apagado (máximo, 127 caracteres)
        -f                      Fuerza el cierre de aplicaciones sin advertir
        -d [p]:xx:yy         Código de motivo de apagado
                                u es el código de usuario
                                p es el código de apagado planeado
                                xx es el código primario del motivo de apagado
                              (entero positivo menor que 256)
                                yy es el código secundario del motivo de apagado

                              (entero positivo menor que 65536)


Ejemplo shutdown -s -t 3600
Con eso se va  a apagar en 1 hora.
Para cancelar usa shutdown -a

GRACIAS POR LEER!!!
1267  Programación / Programación Visual Basic / Re: [RETO] Matriz Bidimensional {FrogMatrix algorithm} en: 30 Noviembre 2010, 19:33 pm
HOLA!!!

ACA LES DEJO MI CODE, MEJORE EL DE LEANDRO A (10% mas rapido en promedio):
(seguro que se puede mejorar la parte que agregue)
si se continua expresando como funcion e imprimiendo las celdas negativas se toma menos tiempo.

Código
  1. Private tmr As CTiming
  2.  
  3.  
  4. Private Function MatriX7913(ByVal N As Integer) As Long()
  5.    Dim M() As Long
  6.    Dim x As Integer, y As Integer, Z As Integer
  7.    Dim AGRUP As Long, TAM As Integer
  8.  
  9.    If N < 1 Then Exit Function
  10.  
  11.    TAM = N - 1
  12.  
  13.    ReDim M(TAM, TAM)
  14.  
  15.    For x = 0 To TAM
  16.        M(x, 0) = x
  17.        M(TAM, x) = TAM
  18.        If TAM > 0 Then
  19.            If Not x = TAM Then
  20.                M(x, 1) = 1 + (x * 2)
  21.                If x = TAM - 2 Then
  22.                    For a = 1 To TAM
  23.                        M(TAM - 1, a) = (TAM * 2) - 1
  24.                    Next
  25.                End If
  26.            End If
  27.        End If
  28.   Next
  29. If TAM > 1 Then
  30. 'GRACIAS LEANDRO A
  31.    For y = 2 To TAM
  32.        For x = 0 To (TAM - 2)
  33.            If x + y > TAM Then
  34.                M(x, y) = M(x, y - 1)
  35.            Else
  36.                AGRUP = 0
  37.                For Z = x To y + x
  38.                    AGRUP = AGRUP + M(Z, y - 1)
  39.                Next
  40.                M(x, y) = AGRUP
  41.            End If
  42.        Next
  43.    Next
  44. 'GRACIAS LEANDRO A
  45. End If
  46.    MatriX7913 = M
  47.  
  48. End Function
  49.  
  50. Private Sub Form_Load()
  51.  Dim M() As Long
  52.  Dim TAMX As Integer, x As Integer, y As Integer
  53.  Set tmr = New CTiming
  54.  
  55.  TAMX = 17
  56.  For FAF = 1 To 10
  57.  tmr.Reset
  58.  M = MatriX7913(TAMX)
  59.  MsgBox tmr.sElapsed
  60.  Next
  61.  For y = 0 To TAMX - 1
  62.        For x = 0 To TAMX - 1
  63.            Debug.Print M(x, y),
  64.        Next
  65.        Debug.Print
  66.  Next
  67.  
  68. End Sub
  69.  

MOD: lo baje a un 15%  ;-) ;-) ;-)

GRACIAS POR LEER!!!
1268  Programación / Programación Visual Basic / Re: Ayuda porfavor algo simple que no se en: 25 Noviembre 2010, 17:06 pm
HOLA!!!

NightMore:
Jajaja, la verdad no entendi nada de lo que digiste, pero gracias  ;D.
Mejor que te haya servido :D.

GRACIAS POR LEER!!!
1269  Programación / Programación Visual Basic / Re: Ayuda con Visual Basic, crear un BOT en: 25 Noviembre 2010, 12:15 pm
HOLA!!!

Hola, para simular los clicks del mouse usa el API MOUSE_EVENT.
Y para escribir un texto la funcion SENDKEYS.

Suerte avisame si necesitas mas info.


GRACIAS POR LEER!!!
1270  Programación / Programación Visual Basic / Re: [Aporte] mINI.bas - Guardar Variables en un Archivo INI. Permite Multilinea en: 24 Noviembre 2010, 19:43 pm
HOLA!!!

Pregunta de ignorante, que diferencia tengo en guardar las variables en un *.ini a un archivo de texto plano que no sea *.ini .
Por que yo, en mis programas me manejo con un archivo de texto variables.hip en el cual mediante el index del item me doy cuenta que variable es (leo mediante input).

GRACIAS POR LEER!!!
Páginas: 1 ... 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 [127] 128 129 130 131 132 133 134 135 136 137
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines