Luz ambiente en VB
Publicado por Maniel (1 intervención) el 25/08/2013 18:39:52
Pues como dice el titulo estoy programando un equipo de luz de ambiente en VB pero he llegado al punto de querer hacerlo compatible para diferentes monitores mediante un menu de opcciones donde establecer el lugar de lectura de color.
El codigo del form principal es el siguiente:
El programa toma 30 pixeles de la pantalla ubicados en 6 puntos diferentes de la pantalla tomando así 5 pixeles por cada punto y calculando el color medio de esos 5 pixeles para halllar un valor aproximado a lo que se esta viendo en pantalla, el problema viene a la hora de ubicar esos puntos en la pantalla, así como esta si se sustitullen las variables ACIX, ACIY(etc) por valores numericos el programa funciona pero al dejarlo así y haciendo que tome los valores del form2 el programa no realiza ninguna medición del color. Espero que alguien con conocimentos suficientes me ayude a resolver este pequeño problema. Gracias de antemano y un saludo. Pd: Si alguien quiere el proyecto completo no tengo problema por compartirlo.
El codigo del form principal es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
Dim AICX As Integer
Dim AICY As Integer
Dim ACCX As Integer
Dim ACCY As Integer
Dim ADCX As Integer
Dim ADCY As Integer
Dim IICX As Integer
Dim IICY As Integer
Dim ICCX As Integer
Dim ICCY As Integer
Dim IDCX As Integer
Dim IDCY As Integer
Public Sub Opciones()
AICX = Form2.TextBox1.Text
AICY = Form2.TextBox2.Text
ACCX = Form2.TextBox3.Text
ACCY = Form2.TextBox4.Text
ADCX = Form2.TextBox5.Text
ADCY = Form2.TextBox6.Text
IICX = Form2.TextBox7.Text
IICY = Form2.TextBox8.Text
ICCX = Form2.TextBox9.Text
ICCY = Form2.TextBox10.Text
IDCX = Form2.TextBox11.Text
IDCY = Form2.TextBox12.Text
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Call Opciones()
Timer1.Interval = 200
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Try
Dim lColorAIC As Integer = GetPixel(GetDC(0), AICX, AICY)
Dim lColorAI1 As Integer = GetPixel(GetDC(0), AICX - 5, AICY)
Dim lColorAI2 As Integer = GetPixel(GetDC(0), AICX + 5, AICY)
Dim lColorAI3 As Integer = GetPixel(GetDC(0), AICX, AICY - 5)
Dim lColorAI4 As Integer = GetPixel(GetDC(0), AICX, AICY +5)
Dim lColorACC As Integer = GetPixel(GetDC(0), ACCX, ACCY)
Dim lColorAC1 As Integer = GetPixel(GetDC(0), ACCX - 5, ACCY)
Dim lColorAC2 As Integer = GetPixel(GetDC(0), ACCX + 5, ACCY)
Dim lColorAC3 As Integer = GetPixel(GetDC(0), ACCX, ACCY - 5)
Dim lColorAC4 As Integer = GetPixel(GetDC(0), ACCX, ACCY + 5)
Dim lColorADC As Integer = GetPixel(GetDC(0), ADCX, ADCY)
Dim lColorAD1 As Integer = GetPixel(GetDC(0), ADCX - 5, ADCY)
Dim lColorAD2 As Integer = GetPixel(GetDC(0), ADCX + 5, ADCY)
Dim lColorAD3 As Integer = GetPixel(GetDC(0), ADCX, ADCY - 5)
Dim lColorAD4 As Integer = GetPixel(GetDC(0), ADCX, ADCY + 5)
Dim lColorIIC As Integer = GetPixel(GetDC(0), IICX, IICY)
Dim lColorII1 As Integer = GetPixel(GetDC(0), IICX - 5, IICY)
Dim lColorII2 As Integer = GetPixel(GetDC(0), IICX + 5, IICY)
Dim lColorII3 As Integer = GetPixel(GetDC(0), IICX, IICY - 5)
Dim lColorII4 As Integer = GetPixel(GetDC(0), IICX, IICY + 5)
Dim lColorICC As Integer = GetPixel(GetDC(0), ICCX, ICCY)
Dim lColorIC1 As Integer = GetPixel(GetDC(0), ICCX - 5, ICCY)
Dim lColorIC2 As Integer = GetPixel(GetDC(0), ICCX + 5, ICCY)
Dim lColorIC3 As Integer = GetPixel(GetDC(0), ICCX, ICCY - 5)
Dim lColorIC4 As Integer = GetPixel(GetDC(0), ICCX, ICCY + 5)
Dim lColorIDC As Integer = GetPixel(GetDC(0), IDCX, IDCY)
Dim lColorID1 As Integer = GetPixel(GetDC(0), IDCX - 5, IDCY)
Dim lColorID2 As Integer = GetPixel(GetDC(0), IDCX + 5, IDCY)
Dim lColorID3 As Integer = GetPixel(GetDC(0), IDCX, IDCY - 5)
Dim lColorID4 As Integer = GetPixel(GetDC(0), IDCX, IDCY + 5)
Dim Value1 As Long = lColorAIC
Dim R1 As Integer = Value1 Mod 256
Dim G1 As Integer = Int(Value1 / 256) Mod 256
Dim B1 As Integer = Int(Value1 / 256 / 256) Mod 256
Dim Value2 As Long = lColorAI1
Dim R2 As Integer = Value2 Mod 256
Dim G2 As Integer = Int(Value2 / 256) Mod 256
Dim B2 As Integer = Int(Value2 / 256 / 256) Mod 256
Dim Value3 As Long = lColorAI2
Dim R3 As Integer = Value3 Mod 256
Dim G3 As Integer = Int(Value3 / 256) Mod 256
Dim B3 As Integer = Int(Value3 / 256 / 256) Mod 256
Dim Value4 As Long = lColorAI3
Dim R4 As Integer = Value4 Mod 256
Dim G4 As Integer = Int(Value4 / 256) Mod 256
Dim B4 As Integer = Int(Value4 / 256 / 256) Mod 256
Dim Value5 As Long = lColorAI4
Dim R5 As Integer = Value5 Mod 256
Dim G5 As Integer = Int(Value5 / 256) Mod 256
Dim B5 As Integer = Int(Value5 / 256 / 256) Mod 256
Dim RMAI As Integer = (R1 + R2 + R3 + R4 + R5) / 5
Dim GMAI As Integer = (G1 + G2 + G3 + G4 + G5) / 5
Dim BMAI As Integer = (B1 + B2 + B3 + B4 + B5) / 5
Dim ValueMAI As Long = RGB(RMAI, GMAI, BMAI)
Dim Value6 As Long = lColorACC
Dim R6 As Integer = Value6 Mod 256
Dim G6 As Integer = Int(Value6 / 256) Mod 256
Dim B6 As Integer = Int(Value6 / 256 / 256) Mod 256
Dim Value7 As Long = lColorAC1
Dim R7 As Integer = Value7 Mod 256
Dim G7 As Integer = Int(Value7 / 256) Mod 256
Dim B7 As Integer = Int(Value7 / 256 / 256) Mod 256
Dim Value8 As Long = lColorAC2
Dim R8 As Integer = Value8 Mod 256
Dim G8 As Integer = Int(Value8 / 256) Mod 256
Dim B8 As Integer = Int(Value8 / 256 / 256) Mod 256
Dim Value9 As Long = lColorAC3
Dim R9 As Integer = Value9 Mod 256
Dim G9 As Integer = Int(Value9 / 256) Mod 256
Dim B9 As Integer = Int(Value9 / 256 / 256) Mod 256
Dim Value10 As Long = lColorAC4
Dim R10 As Integer = Value10 Mod 256
Dim G10 As Integer = Int(Value10 / 256) Mod 256
Dim B10 As Integer = Int(Value10 / 256 / 256) Mod 256
Dim RMAC As Integer = (R6 + R7 + R8 + R9 + R10) / 5
Dim GMAC As Integer = (G6 + G7 + G8 + G9 + G10) / 5
Dim BMAC As Integer = (B6 + B7 + B8 + B9 + B10) / 5
Dim ValueMAC As Long = RGB(RMAC, GMAC, BMAC)
Dim Value11 As Long = lColorADC
Dim R11 As Integer = Value11 Mod 256
Dim G11 As Integer = Int(Value11 / 256) Mod 256
Dim B11 As Integer = Int(Value11 / 256 / 256) Mod 256
Dim Value12 As Long = lColorAD1
Dim R12 As Integer = Value12 Mod 256
Dim G12 As Integer = Int(Value12 / 256) Mod 256
Dim B12 As Integer = Int(Value12 / 256 / 256) Mod 256
Dim Value13 As Long = lColorAD2
Dim R13 As Integer = Value13 Mod 256
Dim G13 As Integer = Int(Value13 / 256) Mod 256
Dim B13 As Integer = Int(Value13 / 256 / 256) Mod 256
Dim Value14 As Long = lColorAD3
Dim R14 As Integer = Value14 Mod 256
Dim G14 As Integer = Int(Value14 / 256) Mod 256
Dim B14 As Integer = Int(Value14 / 256 / 256) Mod 256
Dim Value15 As Long = lColorAD4
Dim R15 As Integer = Value5 Mod 256
Dim G15 As Integer = Int(Value15 / 256) Mod 256
Dim B15 As Integer = Int(Value15 / 256 / 256) Mod 256
Dim RMAD As Integer = (R11 + R12 + R13 + R14 + R15) / 5
Dim GMAD As Integer = (G11 + G12 + G13 + G14 + G15) / 5
Dim BMAD As Integer = (B11 + B12 + B13 + B14 + B15) / 5
Dim ValueMAD As Long = RGB(RMAD, GMAD, BMAD)
Dim Value16 As Long = lColorIIC
Dim R16 As Integer = Value16 Mod 256
Dim G16 As Integer = Int(Value16 / 256) Mod 256
Dim B16 As Integer = Int(Value16 / 256 / 256) Mod 256
Dim Value17 As Long = lColorII1
Dim R17 As Integer = Value17 Mod 256
Dim G17 As Integer = Int(Value17 / 256) Mod 256
Dim B17 As Integer = Int(Value17 / 256 / 256) Mod 256
Dim Value18 As Long = lColorII2
Dim R18 As Integer = Value18 Mod 256
Dim G18 As Integer = Int(Value18 / 256) Mod 256
Dim B18 As Integer = Int(Value18 / 256 / 256) Mod 256
Dim Value19 As Long = lColorII3
Dim R19 As Integer = Value19 Mod 256
Dim G19 As Integer = Int(Value19 / 256) Mod 256
Dim B19 As Integer = Int(Value19 / 256 / 256) Mod 256
Dim Value20 As Long = lColorII4
Dim R20 As Integer = Value20 Mod 256
Dim G20 As Integer = Int(Value20 / 256) Mod 256
Dim B20 As Integer = Int(Value20 / 256 / 256) Mod 256
Dim RMII As Integer = (R16 + R17 + R18 + R19 + R20) / 5
Dim GMII As Integer = (G16 + G17 + G18 + G19 + G20) / 5
Dim BMII As Integer = (B16 + B17 + B18 + B19 + B20) / 5
Dim ValueMII As Long = RGB(RMII, GMII, BMII)
Dim Value21 As Long = lColorICC
Dim R21 As Integer = Value21 Mod 256
Dim G21 As Integer = Int(Value21 / 256) Mod 256
Dim B21 As Integer = Int(Value21 / 256 / 256) Mod 256
Dim Value22 As Long = lColorIC1
Dim R22 As Integer = Value22 Mod 256
Dim G22 As Integer = Int(Value22 / 256) Mod 256
Dim B22 As Integer = Int(Value22 / 256 / 256) Mod 256
Dim Value23 As Long = lColorIC2
Dim R23 As Integer = Value23 Mod 256
Dim G23 As Integer = Int(Value23 / 256) Mod 256
Dim B23 As Integer = Int(Value23 / 256 / 256) Mod 256
Dim Value24 As Long = lColorIC3
Dim R24 As Integer = Value24 Mod 256
Dim G24 As Integer = Int(Value24 / 256) Mod 256
Dim B24 As Integer = Int(Value24 / 256 / 256) Mod 256
Dim Value25 As Long = lColorIC4
Dim R25 As Integer = Value25 Mod 256
Dim G25 As Integer = Int(Value25 / 256) Mod 256
Dim B25 As Integer = Int(Value25 / 256 / 256) Mod 256
Dim RMIC As Integer = (R21 + R22 + R23 + R24 + R25) / 5
Dim GMIC As Integer = (G21 + G22 + G23 + G24 + G25) / 5
Dim BMIC As Integer = (B21 + B22 + B23 + B24 + B25) / 5
Dim ValueMIC As Long = RGB(RMIC, GMIC, BMIC)
Dim Value26 As Long = lColorIDC
Dim R26 As Integer = Value26 Mod 256
Dim G26 As Integer = Int(Value26 / 256) Mod 256
Dim B26 As Integer = Int(Value26 / 256 / 256) Mod 256
Dim Value27 As Long = lColorID1
Dim R27 As Integer = Value27 Mod 256
Dim G27 As Integer = Int(Value27 / 256) Mod 256
Dim B27 As Integer = Int(Value27 / 256 / 256) Mod 256
Dim Value28 As Long = lColorID2
Dim R28 As Integer = Value28 Mod 256
Dim G28 As Integer = Int(Value28 / 256) Mod 256
Dim B28 As Integer = Int(Value28 / 256 / 256) Mod 256
Dim Value29 As Long = lColorID3
Dim R29 As Integer = Value29 Mod 256
Dim G29 As Integer = Int(Value29 / 256) Mod 256
Dim B29 As Integer = Int(Value29 / 256 / 256) Mod 256
Dim Value30 As Long = lColorID4
Dim R30 As Integer = Value30 Mod 256
Dim G30 As Integer = Int(Value30 / 256) Mod 256
Dim B30 As Integer = Int(Value30 / 256 / 256) Mod 256
Dim RMID As Integer = (R26 + R27 + R28 + R29 + R30) / 5
Dim GMID As Integer = (G26 + G27 + G28 + G29 + G30) / 5
Dim BMID As Integer = (B26 + B27 + B28 + B29 + B30) / 5
Dim ValueMID As Long = RGB(RMID, GMID, BMID)
PictureBox1.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMAI)
PictureBox2.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMAC)
PictureBox3.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMAD)
PictureBox4.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMII)
PictureBox5.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMIC)
PictureBox6.BackColor = System.Drawing.ColorTranslator.FromOle(ValueMID)
Catch
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = False
Form2.Show()
End Sub
End Class
El programa toma 30 pixeles de la pantalla ubicados en 6 puntos diferentes de la pantalla tomando así 5 pixeles por cada punto y calculando el color medio de esos 5 pixeles para halllar un valor aproximado a lo que se esta viendo en pantalla, el problema viene a la hora de ubicar esos puntos en la pantalla, así como esta si se sustitullen las variables ACIX, ACIY(etc) por valores numericos el programa funciona pero al dejarlo así y haciendo que tome los valores del form2 el programa no realiza ninguna medición del color. Espero que alguien con conocimentos suficientes me ayude a resolver este pequeño problema. Gracias de antemano y un saludo. Pd: Si alguien quiere el proyecto completo no tengo problema por compartirlo.
Valora esta pregunta


0