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

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 ... 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 [701] 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 ... 1236
7001  Programación / .NET (C#, VB.NET, ASP) / Re: Crear una consola por hilo. en: 12 Julio 2014, 21:16 pm
Una alternativa bastante sucia, dada la prohibición de adjuntar más de 1 consola por proceso, podría ser esta:

Por cada thread que inicies, ejecutas una CMD (instanciando la Class Process, nada de adjuntar mediante la WinAPI), y ya tendrías una consola "adjuntada" y distinta por cada thread, con todo el control necesario para escribir en el Buffer de cada una de ellas.

Saludos.
7002  Programación / .NET (C#, VB.NET, ASP) / Re: Duda con excepciones en .NET en: 12 Julio 2014, 17:10 pm
Puedes obtener el nombre del método que lanzó la excepcion, utilizando la propiedad Exception.TargetSite.

Citar
Gets the method that throws the current exception.

Nota: Pero antes de pensar en usarlo para todas las circunstancias, deberías leer las "Remarks" del MSDN.

Ejemplo de uso:

Código
  1. Public Class Form1
  2.  
  3.    Private Sub Test() Handles MyBase.Shown
  4.  
  5.        Try
  6.            Me.Method1()
  7.            Me.Method2()
  8.  
  9.        Catch ex As Exception
  10.            MessageBox.Show(String.Format("Nombre del método: {0}", ex.TargetSite.Name))
  11.  
  12.        End Try
  13.  
  14.    End Sub
  15.  
  16.    Private Sub Method1()
  17.        Exit Sub
  18.        Throw New InvalidOperationException
  19.    End Sub
  20.  
  21.    Private Sub Method2()
  22.        Throw New InvalidOperationException
  23.    End Sub
  24.  
  25. End Class

PD: También está disponible el nombre del método en el StackTrace, pero deberías parsear el String resultante, solo te lo comento como dato adicional porque sería una tontería hacer eso, ya que TargetSite obtiene el nombre desde el StackTrace, así que además si el StackTrace está vacío tampoco habrá un TargetSite accesible.

Saludos.
7003  Programación / .NET (C#, VB.NET, ASP) / Re: Bueno insisto con la dichosa rueda de combinaciones :) en: 12 Julio 2014, 16:23 pm
Pondria el documento que tengo pero es un pdf y no se como hacerlo

http://es.scribd.com/upload-document

o:

http://docs.google.com
7004  Programación / .NET (C#, VB.NET, ASP) / Re: Bueno insisto con la dichosa rueda de combinaciones :) en: 12 Julio 2014, 11:28 am
¿Puedes proporcionar una url con un "juego" o un servico de combinaciones real donde se utilice ese algoritmo?.

Sinceramente, no se o no me viene a la cabeza que es eso de la "rueda de códigos infantil" ni "rueda cargada" xD.
7005  Programación / .NET (C#, VB.NET, ASP) / Re: Combinaciones numericas por posicion con numeros guias en: 12 Julio 2014, 11:14 am
Como ya te expliqué sería mejor que te guiases por el código de antes y hacerle las modificaciones que resulten necesarias (lo digo por el nuevo post que has publicado con un código muy distinto), creo que tú entiendes mejor que yo el resultado que esperas obtener...

Mira a ver si es esto lo que quieres:

Establezco los números "guía" con sus números "asociados" (solo 20 guías), luego hago 80 combinaciones con los números "asociados" con una longitud de 6 números, y luego ordeno cada combinación de menor a mayor.
Si algo de lo que acabo de comentar no es correcto, intenta ser específico.

PD: Pueden darse combinaciones repetidas, pero una vez aclarado, en caso de que sea esto lo que buscas, entonces te diré como eliminar repetidas.

Código
  1. Public Class ComboTest : Inherits Form
  2.  
  3. #Region " Objects, Vars "
  4.  
  5.    ' La Class "Random", es necesaria para desordenar una colección
  6.    ' y esta declaración tiene que ir siempre fuera de cualquier Sub.
  7.    Private ComboRandomizer As New Random
  8.  
  9.    ' El control que creo en tiempo de ejecución, donde mostraré las combinaciones.
  10.    Private rtb As New RichTextBox With
  11.            {
  12.              .Dock = DockStyle.Fill,
  13.              .Font = New Font("Lucida Console", 10.0F)
  14.            }
  15.  
  16.    ' Una "palanca" para habilitar/deshabilitar el bloque de depuración.
  17.    Private EnableDebug As Boolean = False
  18.  
  19.    ' Instancio una lista donde iremos guardando cada combinación obtenida.
  20.    Private Combos As New List(Of Integer())
  21.  
  22.    ' Otra lista donde le daré el formato deseado a los números.
  23.    Dim ComboStrings As List(Of String) = Nothing
  24.  
  25.    ' El máximo de combinaciones.
  26.    Private Property MaxCombos As Integer = 80I
  27.  
  28.    ' El máximo de longitud para cada combinación.
  29.    Private Property MaxComboLength As Integer = 6I
  30.  
  31.    ' Los números "guías" que usaremos para rellenar cada combinación.
  32.    'Private ReadOnly Numbers As Integer() =
  33.    '    (From n As Integer In
  34.    '     ("01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20-" &
  35.    '      "21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-" &
  36.    '      "41-42-43-44-45-46-47-48-49-50"
  37.    '     ).Split({"-"}, StringSplitOptions.RemoveEmptyEntries)).ToArray
  38.  
  39.    ' Izquierda: Número "guía"
  40.    ' Derecha: Número asociado
  41.    Private ReadOnly NumberWheel As New Dictionary(Of Integer, Integer) From
  42.      {
  43.          {1, 21}, {2, 22}, {3, 23}, {4, 24}, {5, 25},
  44.          {6, 26}, {7, 27}, {8, 28}, {9, 29}, {10, 30},
  45.          {11, 31}, {12, 32}, {13, 33}, {14, 34}, {15, 35},
  46.          {16, 36}, {17, 37}, {18, 38}, {19, 39}, {20, 40}
  47.      }
  48.  
  49. #End Region
  50.  
  51. #Region " Constructors "
  52.  
  53.    ' De este Sub no hagas caso, es el constructor del Form.
  54.    Public Sub New()
  55.  
  56.        ' This call is required by the designer.
  57.        ' Add any initialization after the InitializeComponent() call.
  58.        InitializeComponent()
  59.  
  60.        With Me
  61.            ' Seteo algunas propiedades sin imortancia.
  62.            .Size = New Point(320, 480)
  63.            .StartPosition = FormStartPosition.CenterScreen
  64.            ' Añado el control al Form.
  65.            .Controls.Add(rtb)
  66.        End With
  67.  
  68.    End Sub
  69.  
  70. #End Region
  71.  
  72. #Region " Event-Handlers "
  73.  
  74.    Private Sub ComboTest() Handles MyBase.Shown
  75.  
  76.        Me.DoCombos()
  77.        Me.PrintCombos()
  78.  
  79.    End Sub
  80.  
  81. #End Region
  82.  
  83. #Region " Methods "
  84.  
  85.    ' La función que se encarga de desordenar y devolverte una combinación.
  86.    ' By Elektro.
  87.    'Friend Function GetRandomCombination(Of T)(ByVal [Collection] As IEnumerable(Of T),
  88.    '                                          ByVal [Length] As Integer) As IEnumerable(Of T)
  89.  
  90.    '    Return (From Item As T In [Collection]
  91.    '            Order By ComboRandomizer.Next
  92.    '            Take [Length]).ToArray
  93.  
  94.    'End Function
  95.  
  96.    Friend Function GetRandomCombination(Of T)([Collection] As Dictionary(Of T, T),
  97.                                               [Length] As Integer) As IEnumerable(Of T)
  98.  
  99.        Return (From Item As KeyValuePair(Of T, T) In [Collection]
  100.                Select Item.Value
  101.                Order By ComboRandomizer.Next
  102.                Take [Length]).ToArray
  103.  
  104.    End Function
  105.  
  106.    Private Sub DoCombos()
  107.  
  108.        ' Añadir combinaciones a la lista, hasta que la lista tenga 'MaxComboLength' (80) elementos.
  109.        Do Until Combos.Count = (MaxCombos - 1)
  110.  
  111.            ' Obtengo una combinación.
  112.            Dim tmpCombo As Integer() = Me.GetRandomCombination(Of Integer)(NumberWheel, MaxComboLength)
  113.  
  114.            ' Ordeno los elementos de la combinación, de menos a mayor.
  115.            Array.Sort(tmpCombo)
  116.  
  117.            ' Añado la combinación a la lista.
  118.            Combos.Add(tmpCombo)
  119.  
  120.        Loop
  121.  
  122.        ' Ordeno los elementos de la lista, basandome en el orden de los elementos de cada Array.
  123.        ' NOTA: Puede tener fallos al ordenar, no aseguro que el orden sea perfecto.
  124.        Combos = (From Combo As Integer() In Combos Order By Convert.ToDecimal(String.Join("", Combo)) Ascending).ToList
  125.        Combos = (From Combo As Integer() In Combos Order By Combo.First Ascending).ToList
  126.  
  127.        ' Además, creo utra lista Strings, para darle formato a cada combo numérico,
  128.        ' y añadirle así un "0" a los números del "1" al "9" y que quede más bonito en la previsualización xD.
  129.        Me.ComboStrings =
  130.            (From Combo In Combos
  131.             Select (String.Join(" | ", From Value As String In Combo
  132.                                       Select If(Value.Length = 1, "0" & Value, Value)))).ToList
  133.  
  134. #If DEBUG Then
  135.  
  136.        ' El bloque de depuración.
  137.        ' Este bloque entero es para testear el formato que le quieras dar.
  138.        If Me.EnableDebug Then
  139.  
  140.            Dim sb As New System.Text.StringBuilder
  141.  
  142.            With sb
  143.  
  144.                For Index As Integer = 0 To (MaxCombos - 1)
  145.  
  146.                    sb.AppendLine(String.Format("Combo sin formato:"))
  147.                    sb.AppendLine(String.Join(", ", Combos(Index)))
  148.                    sb.AppendLine()
  149.                    sb.AppendLine(String.Format("Combo con formato:"))
  150.                    sb.AppendLine(String.Join(", ", ComboStrings(Index)))
  151.  
  152.                    MessageBox.Show(sb.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Information)
  153.  
  154.                    sb.Clear()
  155.  
  156.                Next Index
  157.  
  158.            End With
  159.  
  160.        End If
  161.  
  162. #End If
  163.  
  164.    End Sub
  165.  
  166.    Private Sub PrintCombos()
  167.  
  168.        ' Muestro los Combos en el control.
  169.        With Me.rtb
  170.  
  171.            .SuspendLayout()
  172.            For Each Combo As String In Me.ComboStrings
  173.                .AppendText(Combo)
  174.                .AppendText(Environment.NewLine & New String("-", Combo.Length) & Environment.NewLine)
  175.            Next Combo
  176.            .ResumeLayout()
  177.  
  178.            .Select(0, 0)
  179.  
  180.        End With
  181.  
  182.    End Sub
  183.  
  184. #End Region
  185.  
  186. End Class
  187.  
7006  Programación / .NET (C#, VB.NET, ASP) / Re: Editar texto de un programa a partir de otro programa c# en: 12 Julio 2014, 09:56 am
Si una aplicación no no puede interactuar de forma legítima con otro proceso (Sockets, Remote Object, etc...) cuando ese debería ser su proposito en este caso, entonces está mal desarrollada.

Tu pregunta trata sobre un software que no ha sido desarrollado para la interacción entre procesos, y eso complica las cosas,
la función sendmessage (enviando el message WM_GETTEXT) es algo que se inventó en el siglo pasado cuando las aplicaciones todavía no eran capaces de estar aisladas unas de las otras (cuando el término "isolation" no existía aún en lo referente a la programación de Software), pero en este siglo se debería evitar el uso de la WinAPI para hacer estas cosas, la verdad, al menos NO en caso de que los dos proyectos sean de tu propiedad y eso signifique que puedas editar los proyectos, entonces deberías escuchar la primera sugerencia de @KuBox para buscar otras soluciones.

De todas formas si te empeñas en hacerlo usando la WinAPI (que tampoco es que sea algo malo, pero según se mire es una mala práctica), puedes empezar por buscar y escribir en tu código las declaraciones de todas estas funciones e informarte sobre el uso de ellas, así como el uso de los métodos de Marshal que te pondré al final que también te pueden servir como alternativa, y cuando lo tengas todo listo, ya podremos seguir hablando sobre el tema:

· FindWindowEx function
· WindowFromPoint function
· GetClassName function
· EnumChildWindows function

· SendMessage function
· WM_GETTEXT message
· WM_GETTEXTLENGTH message

· Marshal.AllocHGlobal Method
· Marshal.PtrToStringUni Method

Nota: Ten en cuenta que a cada Control de una aplicación se le asigna un Handle, pero además la zona vacía para escribir en ese Control segúramente tendrá otro Handle distinto.

Nota 2:
Lo he intentado, pero no he conseguido nada..
Al menos yo, al hablar sobre la WinAPI, mientras no muestres un código con tu progreso me limitaré solamente a ofrecerte información.
7007  Programación / Scripting / Re: indetectable en: 11 Julio 2014, 14:06 pm
Los empaquetadores (conversores de "X" a "EXE"), sobre todo si son famosos pero sin buena reputación, suelen estar fichados por todos los antivirus como una "HackTool" o variantes de ese estilo, a pesar de que se usen con buenos fines ...por supuesto se conoce que otras muchas personas utilizan ese tipo de herramientas con fines ilegales.

Puedes probar el Software ExeScript de ScriptCode.com, nunca me dió ese tipo de problemas con Bats ni Vbs's.

De lo contrario, puedes intentar usar Themida o algún otro protector para indetectabilizar (en la medida de lo que sea posible) tu executable.

Saludos.
7008  Programación / .NET (C#, VB.NET, ASP) / Re: Clickar a un color en: 11 Julio 2014, 14:01 pm
Aquí os dejo una versión mejorada y extendida de lo anterior, por si a alguien le sirve:

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 07-11-2014
  4. ' ***********************************************************************
  5. ' <copyright file="PixelUtil.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12.  
  13. ' **************************************************
  14. ' Count the number of Pixels that contains the image
  15. ' **************************************************
  16. '
  17. '' Create a new bitmap.
  18. 'Dim bmp As Bitmap = Bitmap.FromFile("C:\DesktopScreenshot.bmp", False)
  19. '
  20. '' Instance a PixelUtil Class.
  21. 'Dim bmpPixelUtil As New PixelUtil(bmp)
  22. '
  23. '' Display the pixel count.
  24. 'MessageBox.Show(String.Format("Total amount of Pixels: {0}", CStr(bmpPixelUtil.PixelCount)))
  25.  
  26.  
  27. ' ************************************************
  28. ' Searchs for an specific pixel color in the image
  29. ' ************************************************
  30. '
  31. '' Create a new bitmap.
  32. 'Dim bmp As Bitmap = Bitmap.FromFile("C:\DesktopScreenshot.bmp", False)
  33. '
  34. '' Instance a PixelUtil Class.
  35. 'Dim bmpPixelUtil As New PixelUtil(bmp)
  36. '
  37. '' Specify the RGB PixelColor to search.
  38. 'Dim FindColor As Color = Color.FromArgb(255, 174, 201)
  39. '
  40. '' Get the pixel data.
  41. 'Dim FoundPixels As List(Of PixelUtil.PixelData) = bmpPixelUtil.SearchColor(FindColor)
  42. '
  43. '' Loop through each pixel.
  44. 'For Each Pixel As PixelUtil.PixelData In FoundPixels
  45. '
  46. '    Dim sb As New System.Text.StringBuilder
  47. '    With sb
  48. '
  49. '        .AppendLine(String.Format("Index: {0}", CStr(Pixel.Index)))
  50. '        .AppendLine(String.Format("Coord: {0}", Pixel.Coordinates.ToString))
  51. '
  52. '        MessageBox.Show(.ToString, "Pixel-Color Search")
  53. '
  54. '        .Clear()
  55. '
  56. '    End With
  57. '
  58. 'Next Pixel
  59.  
  60.  
  61. ' *********************************************************************
  62. ' Retrieve the index, color, and coordinates of each pixel in the image
  63. ' *********************************************************************
  64. '
  65. '' Create a new bitmap.
  66. 'Dim bmp As Bitmap = Bitmap.FromFile("C:\DesktopScreenshot.bmp", False)
  67. '
  68. '' Instance a PixelUtil Class.
  69. 'Dim bmpPixelUtil As New PixelUtil(bmp)
  70. '
  71. '' Get the pixel data.
  72. 'Dim Pixels As List(Of PixelUtil.PixelData) = bmpPixelUtil.GetPixelData()
  73. '
  74. '' Loop through each pixel.
  75. 'For Each Pixel As PixelUtil.PixelData In Pixels
  76. '
  77. '    Dim sb As New System.Text.StringBuilder
  78. '    With sb
  79. '
  80. '        .AppendLine(String.Format("Index: {0}", CStr(Pixel.Index)))
  81. '        .AppendLine(String.Format("Color: {0}", Pixel.Color.ToString))
  82. '        .AppendLine(String.Format("Coord: {0}", Pixel.Coordinates.ToString))
  83. '
  84. '        MessageBox.Show(.ToString, "Pixel Search")
  85. '
  86. '        .Clear()
  87. '
  88. '    End With
  89. '
  90. 'Next Pixel
  91.  
  92.  
  93. ' ****************************************************************************
  94. ' Retrieve the index, color, and coordinates of a range of pixels in the image
  95. ' ****************************************************************************
  96. '
  97. '' Create a new bitmap.
  98. 'Dim bmp As Bitmap = Bitmap.FromFile("C:\DesktopScreenshot.bmp", False)
  99. '
  100. '' Instance a PixelUtil Class.
  101. 'Dim bmpPixelUtil As New PixelUtil(bmp)
  102. '
  103. '' Specify the pixel range to retrieve.
  104. 'Dim RangeMin As Integer = 1919I
  105. 'Dim RangeMax As Integer = 1921I
  106. '
  107. '' Get the pixel data.
  108. 'Dim FoundPixels As List(Of PixelUtil.PixelData) = bmpPixelUtil.GetPixelData(RangeMin, RangeMax)
  109. '
  110. '' Loop through each pixel.
  111. 'For Each Pixel As PixelUtil.PixelData In FoundPixels
  112. '
  113. '    Dim sb As New System.Text.StringBuilder
  114. '    With sb
  115. '
  116. '        .AppendLine(String.Format("Index: {0}", CStr(Pixel.Index)))
  117. '        .AppendLine(String.Format("Color: {0}", Pixel.Color.ToString))
  118. '        .AppendLine(String.Format("Coord: {0}", Pixel.Coordinates.ToString))
  119. '
  120. '        MessageBox.Show(.ToString, "Pixel-Color Search")
  121. '
  122. '        .Clear()
  123. '
  124. '    End With
  125. '
  126. 'Next Pixel
  127.  
  128.  
  129. #End Region
  130.  
  131. #Region " Imports "
  132.  
  133. Imports System.ComponentModel
  134. Imports System.Drawing.Imaging
  135. Imports System.Runtime.InteropServices
  136.  
  137. #End Region
  138.  
  139. #Region " PixelUtil "
  140.  
  141. Public Class PixelUtil
  142.  
  143. #Region " Vars, Properties "
  144.  
  145.    Private _PixelData As List(Of PixelData) = Nothing
  146.    Private _bmp As Bitmap = Nothing
  147.    Private _PixelCount As Integer = Nothing
  148.  
  149.    ''' <summary>
  150.    ''' Gets the Bitmap object.
  151.    ''' </summary>
  152.    ''' <value>The BMP.</value>
  153.    Public ReadOnly Property bmp As Bitmap
  154.        Get
  155.            Return Me._bmp
  156.        End Get
  157.    End Property
  158.  
  159.    ''' <summary>
  160.    ''' Gets the total amount of pixels that contains the Bitmap.
  161.    ''' </summary>
  162.    ''' <value>The pixel count.</value>
  163.    Public ReadOnly Property PixelCount As Integer
  164.        Get
  165.            Return Me._PixelCount
  166.        End Get
  167.    End Property
  168.  
  169. #End Region
  170.  
  171. #Region " Classes "
  172.  
  173.    ''' <summary>
  174.    ''' Stores specific pixel information of an image.
  175.    ''' </summary>
  176.    Public Class PixelData
  177.  
  178.        ''' <summary>
  179.        ''' Gets or sets the pixel index.
  180.        ''' </summary>
  181.        ''' <value>The pixel index.</value>
  182.        Public Property Index As Integer
  183.  
  184.        ''' <summary>
  185.        ''' Gets or sets the pixel color.
  186.        ''' </summary>
  187.        ''' <value>The pixel color.</value>
  188.        Public Property Color As Color
  189.  
  190.        ''' <summary>
  191.        ''' Gets or sets the pixel coordinates relative to the image.
  192.        ''' </summary>
  193.        ''' <value>The pixel coordinates.</value>
  194.        Public Property Coordinates As Point
  195.  
  196.    End Class
  197.  
  198. #End Region
  199.  
  200. #Region " Constructors "
  201.  
  202.    ''' <summary>
  203.    ''' Prevents a default instance of the <see cref="PixelUtil"/> class from being created.
  204.    ''' </summary>
  205.    Private Sub New()
  206.    End Sub
  207.  
  208.    ''' <summary>
  209.    ''' Initializes a new instance of the <see cref="PixelUtil"/> class.
  210.    ''' </summary>
  211.    ''' <param name="bmp">Indicates the Bitmap image to process it's pixels.</param>
  212.    ''' <exception cref="System.Exception">PixelFormat unsupported.</exception>
  213.    Public Sub New(ByVal bmp As Bitmap)
  214.  
  215.        If Not bmp.PixelFormat = PixelFormat.Format24bppRgb Then
  216.            Throw New Exception("PixelFormat unsupported.")
  217.        End If
  218.  
  219.        Me._bmp = bmp
  220.        Me._PixelCount = Me.[Count]
  221.  
  222.    End Sub
  223.  
  224. #End Region
  225.  
  226. #Region " Public Methods "
  227.  
  228.    ''' <summary>
  229.    ''' Returns a <c>'PixelData'</c> object containing information about each pixel in the image.
  230.    ''' </summary>
  231.    ''' <returns>List(Of PixelData).</returns>
  232.    Public Function GetPixelData() As List(Of PixelData)
  233.  
  234.        If Me._PixelData Is Nothing Then
  235.  
  236.            Me._PixelData = New List(Of PixelData)
  237.  
  238.            ' Lock the Bitmap bits.
  239.            Dim bmpRect As New Rectangle(0, 0, Me._bmp.Width, Me._bmp.Height)
  240.            Dim bmpData As BitmapData = Me._bmp.LockBits(bmpRect, ImageLockMode.ReadWrite, Me._bmp.PixelFormat)
  241.  
  242.            ' Get the address of the first line.
  243.            Dim Pointer As IntPtr = bmpData.Scan0
  244.  
  245.            ' Hold the bytes of the bitmap into a Byte-Array.
  246.            ' NOTE: This code is specific to a bitmap with 24 bits per pixels.
  247.            Dim bmpBytes As Integer = (Math.Abs(bmpData.Stride) * bmpRect.Height)
  248.            Dim rgbData(bmpBytes - 1) As Byte
  249.  
  250.            ' Copy the RGB values into the array.
  251.            Marshal.Copy(Pointer, rgbData, 0, bmpBytes)
  252.  
  253.            ' Unlock the Bitmap bits.
  254.            Me._bmp.UnlockBits(bmpData)
  255.  
  256.            ' Loop through each 24bpp-RGB value.
  257.            For rgbIndex As Integer = 2 To rgbData.Length - 1 Step 3
  258.  
  259.                ' Set the pixel Data.
  260.                Dim Pixel As New PixelData
  261.  
  262.                With Pixel
  263.  
  264.                    .Index = rgbIndex \ 3I
  265.  
  266.                    .Color = Color.FromArgb(red:=rgbData(rgbIndex),
  267.                                            green:=rgbData(rgbIndex - 1I),
  268.                                            blue:=rgbData(rgbIndex - 2I))
  269.  
  270.                    .Coordinates = New Point(X:=(.Index Mod bmpRect.Width),
  271.                                             Y:=(.Index - (.Index Mod bmpRect.Width)) \ bmpRect.Width)
  272.  
  273.                End With
  274.  
  275.                ' Add the PixelData into the list.
  276.                Me._PixelData.Add(Pixel)
  277.  
  278.            Next rgbIndex
  279.  
  280.        End If
  281.  
  282.        Return Me._PixelData
  283.  
  284.    End Function
  285.  
  286.    ''' <summary>
  287.    ''' Returns a <c>'PixelData'</c> object containing information about a range of pixels in the image.
  288.    ''' </summary>
  289.    ''' <returns>List(Of PixelData).</returns>
  290.    ''' <exception cref="System.Exception">Pixel index is out of range</exception>
  291.    Public Function GetPixelData(ByVal RangeMin As Integer,
  292.                                 ByVal RangeMax As Integer) As List(Of PixelData)
  293.  
  294.        If Not (Me._PixelCount >= RangeMin AndAlso Me._PixelCount <= RangeMax) Then
  295.            Throw New Exception("Pixel index is out of range.")
  296.            Return Nothing
  297.        End If
  298.  
  299.        ' Return the Pixel range.
  300.        Return (From Pixel As PixelData In Me.GetPixelData()
  301.                Where (Pixel.Index >= RangeMin AndAlso Pixel.Index <= RangeMax)).ToList
  302.  
  303.    End Function
  304.  
  305.    ''' <summary>
  306.    ''' Searchs for the specified pixel-color inside the image and returns all the matches.
  307.    ''' </summary>
  308.    ''' <param name="PixelColor">Indicates the color to find.</param>
  309.    ''' <returns>List(Of PixelData).</returns>
  310.    Public Function SearchColor(ByVal PixelColor As Color) As List(Of PixelData)
  311.  
  312.        Return (From Pixel As PixelData In Me.GetPixelData
  313.                Where Pixel.Color = PixelColor).ToList
  314.  
  315.    End Function
  316.  
  317. #End Region
  318.  
  319. #Region " Private Methods "
  320.  
  321.    ''' <summary>
  322.    ''' Counts the number of pixels that contains the image.
  323.    ''' </summary>
  324.    ''' <returns>The number of pixels.</returns>
  325.    Private Function [Count]() As Integer
  326.  
  327.        ' Lock the Bitmap bits.
  328.        Dim bmpRect As New Rectangle(0, 0, Me._bmp.Width, Me._bmp.Height)
  329.        Dim bmpData As BitmapData = Me._bmp.LockBits(bmpRect, ImageLockMode.ReadWrite, Me._bmp.PixelFormat)
  330.  
  331.        ' Get the address of the first line.
  332.        Dim Pointer As IntPtr = bmpData.Scan0
  333.  
  334.        ' Hold the bytes of the bitmap into a Byte-Array.
  335.        ' NOTE: This code is specific to a bitmap with 24 bits per pixels.
  336.        Dim bmpBytes As Integer = (Math.Abs(bmpData.Stride) * bmpRect.Height)
  337.        Dim rgbData(bmpBytes - 1) As Byte
  338.  
  339.        ' Copy the RGB values into the array.
  340.        Marshal.Copy(Pointer, rgbData, 0, bmpBytes)
  341.  
  342.        ' Unlock the Bitmap bits.
  343.        Me._bmp.UnlockBits(bmpData)
  344.  
  345.        Return rgbData.Count
  346.  
  347.    End Function
  348.  
  349. #End Region
  350.  
  351. #Region " Hidden Methods "
  352.  
  353.    ''' <summary>
  354.    ''' Serves as a hash function for a particular type.
  355.    ''' </summary>
  356.    <EditorBrowsable(EditorBrowsableState.Never)>
  357.    Public Shadows Sub GetHashCode()
  358.    End Sub
  359.  
  360.    ''' <summary>
  361.    ''' Determines whether the specified System.Object is equal to the current System.Object.
  362.    ''' </summary>
  363.    <EditorBrowsable(EditorBrowsableState.Never)>
  364.    Public Shadows Sub Equals()
  365.    End Sub
  366.  
  367.    ''' <summary>
  368.    ''' Returns a String that represents the current object.
  369.    ''' </summary>
  370.    <EditorBrowsable(EditorBrowsableState.Never)>
  371.    Public Shadows Sub ToString()
  372.    End Sub
  373.  
  374. #End Region
  375.  
  376. End Class
  377.  
  378. #End Region
7009  Programación / .NET (C#, VB.NET, ASP) / Re: Clickar a un color en: 10 Julio 2014, 09:10 am
Te hago la mitad del trabajo, ahora, para ubicar las coordenadas relativas a la imagen por el momento no se me ocurre el modo de hacerlo, pero algo se podrá hacer obteniendo el índice del pixel encontrado (cosa que hago) usandola en alguna fórmula aritmética con el ancho y alto de la imagen.

Public Class PixelData
        Public Index As Integer
        Public Color As Color
        Public Coordinates As Point
    End Class

    Friend Function GetPixelData(ByVal bmp As Bitmap) As List(Of PixelData)

        If Not bmp.PixelFormat = Imaging.PixelFormat.Format24bppRgb Then
            Throw New Exception("PixelFormat no soportado en esta función.")
        End If

        ' Lock the bitmap's bits.  
        Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
        Dim bmpdata As Drawing.Imaging.BitmapData =
            bmp.LockBits(rect, Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)

        ' Get the address of the first line.
        Dim ptr As IntPtr = bmpdata.Scan0

        ' Declare an array to hold the bytes of the bitmap.
        ' This code is specific to a bitmap with 24 bits per pixels.
        Dim bytes As Integer = Math.Abs(bmpdata.Stride) * bmp.Height
        Dim rgbValues(bytes - 1) As Byte

        ' Copy the RGB values into the array.
        Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)

        ' Unlock the bits.
        bmp.UnlockBits(bmpdata)

        ' Set the Data to return.
        Dim Pixels As New List(Of PixelData)

        ' Loop through each 24bpp-RGB value.
        For Index As Integer = 2 To rgbValues.Length - 1 Step 3

            Pixels.Add(New PixelData With
                       {
                           .Index = Index \ 3I,
                           .Color = Color.FromArgb(rgbValues(Index), rgbValues(Index - 1I), rgbValues(Index - 2I)),
                           .Coordinates = Point.Empty
                       })

        Next Index

        Return Pixels

    End Function


EDITO: Fórmula encontrada.

Nota: Lo he testeado con una imagen a resolución 2560x1600, el retorno de datos es practicamente instantaneo, la búsqueda puede variar según lo lejos que se encuentre el pixel en la iteración.

Código
  1.    ''' <summary>
  2.    ''' Stores specific pixel information of an image.
  3.    ''' </summary>
  4.    Friend Class PixelData
  5.  
  6.        ''' <summary>
  7.        ''' Gets or sets the pixel index.
  8.        ''' </summary>
  9.        ''' <value>The pixel index.</value>
  10.        Public Property Index As Integer
  11.  
  12.        ''' <summary>
  13.        ''' Gets or sets the pixel color.
  14.        ''' </summary>
  15.        ''' <value>The pixel color.</value>
  16.        Public Property Color As Color
  17.  
  18.        ''' <summary>
  19.        ''' Gets or sets the pixel coordinates relative to the image.
  20.        ''' </summary>
  21.        ''' <value>The pixel coordinates.</value>
  22.        Public Property Coordinates As Point
  23.  
  24.    End Class
  25.  
  26.    ''' <summary>
  27.    ''' Returns a <c>'PixelData'</c> object containing information about each pixel of an image.
  28.    ''' </summary>
  29.    ''' <param name="bmp">Indicates the Bitmap image to process.</param>
  30.    ''' <returns>List(Of PixelData).</returns>
  31.    ''' <exception cref="System.Exception">PixelFormat unsupported.</exception>
  32.    Friend Function GetPixelData(ByVal bmp As Bitmap) As List(Of PixelData)
  33.  
  34.        If Not bmp.PixelFormat = Imaging.PixelFormat.Format24bppRgb Then
  35.            Throw New Exception("PixelFormat unsupported.")
  36.        End If
  37.  
  38.        ' Lock the Bitmap bits.
  39.        Dim bmpRect As New Rectangle(0, 0, bmp.Width, bmp.Height)
  40.        Dim bmpData As Drawing.Imaging.BitmapData =
  41.            bmp.LockBits(bmpRect, Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)
  42.  
  43.        ' Get the address of the first line.
  44.        Dim Pointer As IntPtr = bmpData.Scan0
  45.  
  46.        ' Hold the bytes of the bitmap into a Byte-Array.
  47.        ' NOTE: This code is specific to a bitmap with 24 bits per pixels.
  48.        Dim bmpBytes As Integer = (Math.Abs(bmpData.Stride) * bmpRect.Height)
  49.        Dim rgbData(bmpBytes - 1) As Byte
  50.  
  51.        ' Copy the RGB values into the array.
  52.        Runtime.InteropServices.Marshal.Copy(Pointer, rgbData, 0, bmpBytes)
  53.  
  54.        ' Unlock the Bitmap bits.
  55.        bmp.UnlockBits(bmpData)
  56.  
  57.        ' Instance the object to return.
  58.        Dim Pixels As New List(Of PixelData)
  59.  
  60.        ' Loop through each 24bpp-RGB value.
  61.        For rgbIndex As Integer = 2 To rgbData.Length - 1 Step 3
  62.  
  63.            ' Get the pixel values.
  64.            Dim PixelIndex As Integer = rgbIndex \ 3I
  65.            Dim PixelCoordX As Integer = PixelIndex Mod bmpRect.Width
  66.            Dim PixelCoordY As Integer = (PixelIndex - PixelCoordX) \ bmpRect.Width
  67.            Dim PixelColorR As Short = rgbData(rgbIndex)
  68.            Dim PixelColorG As Short = rgbData(rgbIndex - 1I)
  69.            Dim PixelColorB As Short = rgbData(rgbIndex - 2I)
  70.  
  71.            ' Set the pixel Data.
  72.            Dim Pixel As New PixelData
  73.            With Pixel
  74.                .Index = PixelIndex
  75.                .Color = Color.FromArgb(PixelColorR, PixelColorG, PixelColorB)
  76.                .Coordinates = New Point(PixelCoordX, PixelCoordY)
  77.            End With
  78.  
  79.            ' Add the PixelData into the list.
  80.            Pixels.Add(Pixel)
  81.  
  82.        Next rgbIndex
  83.  
  84.        Return Pixels
  85.  
  86.    End Function

Ejemplo de uso:

Código
  1.    Public Sub Test() Handles Button1.Click
  2.  
  3.        ' Create a new bitmap.
  4.        Dim bmp As Bitmap = Bitmap.FromFile("Imagen de la pantalla.bmp", False)
  5.  
  6.        ' Specify the RGB PixelColor to search.
  7.        Dim FindColor As Color = Color.FromArgb(255, 174, 201)
  8.  
  9.        ' Get the pixel data.
  10.        Dim Pixels As List(Of PixelData) = Me.GetPixelData(bmp)
  11.  
  12.        ' Loop through each pixel.
  13.        For Each Pixel As PixelData In Pixels
  14.  
  15.            If Pixel.Color.Equals(FindColor) Then
  16.  
  17.                Dim sb As New System.Text.StringBuilder
  18.                With sb
  19.  
  20.                    .AppendLine(String.Format("Index: {0}", CStr(Pixel.Index)))
  21.                    .AppendLine(String.Format("Color: {0}", Pixel.Color.ToString))
  22.                    .AppendLine(String.Format("Coord: {0}", Pixel.Coordinates.ToString))
  23.  
  24.                    MessageBox.Show(.ToString, "Pixel Search")
  25.  
  26.                    .Clear()
  27.  
  28.                End With
  29.  
  30.            End If
  31.  
  32.        Next Pixel
  33.  
  34.    End Sub

Saludos
7010  Informática / Hardware / Re: ¿ Cooler bueno, económico, y silencioso para CPU AMD Socket AM3+ ? en: 9 Julio 2014, 14:58 pm
Bueno, necesitaba una respuesta rápida (por miedo a que el problema fuese a mayores) y como no he podido obtener la ayuda que necesitaba, ya me respondo a mi mismo.

Al final, basandome en los comentarios de varios productos, he decidido comprado un Cooler Master Hyper 212 EVO.



Me podría haber permitido comprar un Cooler más caro, pero sin haber obtenido una opinión experta pues...tampoco voy a arriesgarme sin saber si hacia bien o mal, lo caro no siempre resulta mejor.

PD: Si alquien quiere que le cuente mi experiencia sobre el producto, después de haberlo instalado, que lo comente y con gusto le describiré los detalles.

Saludos!
Páginas: 1 ... 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 [701] 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines