Una familia de software de hoja de cálculo de Microsoft con herramientas para analizar, trazar y comunicar datos.
Esto es lo que tengo.
El programa permite (re)generar la imagen por x (se genera toda una columna), por ordenadas (se generar toda una fila) o por puntos (la imagen se genera punto a punto).
Me falta la rutina para capturar el color del pixel de la imagen que quiero generar.
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
' devuelve el device context del area del cliente de la ventana
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
' devuelve el device context de toda la ventana
Private Declare Function GetWindowDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nindex As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetPixel Lib "gdi32" ( _
ByVal hDC As Long, ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" ( _
ByVal hDC As Long, ByVal x As Long, _
ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Sub p()
GenerarCoordenadas 500, 500
Barajar 500, 500
GenerarImagen "xy" ' valores validos x, y, xy
End Sub
Private Sub GenerarImagen(Tipo As String)
Dim x As Long ' abscisa
Dim y As Long ' ordenada
Dim hDC As Long ' handle device context
Dim hdc1 As Long ' handle device context
Dim hExcel As Long
Dim r As Byte
Dim g As Byte
Dim b As Byte
Dim i As Long
Dim j As Long
Dim H As Worksheet
Dim Color As Long
Dim hwnd As Long
Dim rango As Range
Dim xy() As String
Set H = Worksheets("Hoja1")
H.Activate
hExcel = Application.hwnd
' hdc = GetDC(0) ' consola
hDC = GetDC(hExcel)
hdc1 = GetWindowDC(hExcel)
With H
Select Case Tipo
Case "x"
For i = 2 To .Cells(1, 1).End(xlDown).Row
x = .Cells(i, 1)
For j = 2 To .Cells(1, 2).End(xlDown).Row
y = .Cells(j, 2)
Color = GetPixel(hdc1, x + 500, y + 350)
' r = Int((256) * Rnd)
' g = Int((256) * Rnd)
' b = Int((256) * Rnd)
' SetPixel hdc, x, y, Color
SetPixel hdc1, x + 500, y + 350, vbYellow
' SetPixel hdc, x, y, RGB(r, g, b)
Next
Next
ReleaseDC 0, hDC
Case "y"
For i = 2 To .Cells(1, 2).End(xlDown).Row
y = .Cells(i, 1)
For j = 2 To .Cells(1, 1).End(xlDown).Row
x = .Cells(j, 2)
Color = GetPixel(hdc1, x + 500, y + 350)
' r = Int((256) * Rnd)
' g = Int((256) * Rnd)
' b = Int((256) * Rnd)
' SetPixel hdc, x, y, Color
SetPixel hdc1, x + 500, y + 350, vbYellow
' SetPixel hdc, x, y, RGB(r, g, b)
Next
Next
ReleaseDC 0, hDC
Case "xy"
For i = 2 To .Cells(1, 3).End(xlDown).Row
xy = Split(.Cells(i, 3), ";")
x = CLng(xy(0))
y = CLng(xy(1))
' Color = GetPixel(hdc1, x + 500, y + 350)
r = Int((256) * Rnd)
g = Int((256) * Rnd)
b = Int((256) * Rnd)
' SetPixel hdc1, x + 500, y + 350, vbYellow
SetPixel hdc1, x + 500, y + 350, RGB(r, g, b)
' Sleep 10 ' congela la ejecución
Next
ReleaseDC 0, hDC
End Select
End With
End Sub
Sub Barajar(x As Long, y As Long)
Dim i As Long
Dim j As Long
Dim H As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim Temp As String
Set H = Worksheets("Hoja1")
With H
' barajo la x
For i = 2 To .Cells(1, 1).End(xlDown).Row
f1 = Int(x * Rnd + 2)
If f1 < 2 Or f1 > x + 1 Then
MsgBox "parar"
End If
Temp = .Cells(i, 1)
.Cells(i, 1) = .Cells(f1, 1)
.Cells(f1, 1) = Temp
Next
' barajo la y
For i = 2 To .Cells(1, 2).End(xlDown).Row
f2 = Int(y * Rnd + 2)
If f2 < 2 Or f2 > y + 1 Then
MsgBox "parar"
End If
Temp = .Cells(i, 2)
.Cells(i, 2) = .Cells(f2, 2)
.Cells(f2, 2) = Temp
Next
' barajo la xy
For i = 2 To .Cells(1, 3).End(xlDown).Row
f2 = Int(x * y * Rnd + 2)
If f2 < 2 Or f2 > x * y + 1 Then
MsgBox "parar"
End If
Temp = .Cells(i, 3)
.Cells(i, 3) = .Cells(f2, 3)
.Cells(f2, 3) = Temp
Next
End With
End Sub
Sub LeerPixeles()
Dim H2 As Worksheet
Dim sh As Shape
Dim Celda As Range
Set H2 = Worksheets("Hoja2")
Set Celda = H2.Cells(1, 1)
Debug.Print H2.Type
Debug.Print Celda.Parent.Type
End Sub
Sub GenerarCoordenadas(x As Long, y As Long)
Dim i As Long
Dim j As Long
Dim f As Long
Dim H As Worksheet
Set H = Worksheets("Hoja1")
With H
' borro datos anteriores
.Rows("2:1000000").Delete
' coordenadas x
For i = 1 To x
.Cells(i + 1, 1) = i
Next
' coordenadas y
For i = 1 To y
.Cells(i + 1, 2) = i
Next
' coordenadas xy
f = 2
For i = 1 To x
For j = 1 To y
.Cells(f, 3) = i & ";" & j
f = f + 1
Next
Next
End With
End Sub