回答編集履歴
4
もうちょっとPythonicに
test
CHANGED
@@ -12,11 +12,9 @@
|
|
12
12
|
|
13
13
|
gdi32 = windll.LoadLibrary("gdi32.dll")
|
14
14
|
|
15
|
-
hdc = user32.GetDC(None)
|
16
15
|
|
17
16
|
|
18
|
-
|
19
|
-
def getrgb(x, y):
|
17
|
+
def getrgb(x, y, hdc=user32.GetDC(None)):
|
20
18
|
|
21
19
|
bgr = gdi32.GetPixel(hdc, x, y)
|
22
20
|
|
3
ちゃんと速さを追い求めて
test
CHANGED
@@ -8,21 +8,23 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
x, y = 10, 10
|
12
|
-
|
13
|
-
|
14
|
-
|
15
11
|
user32 = windll.LoadLibrary("user32.dll")
|
16
12
|
|
17
13
|
gdi32 = windll.LoadLibrary("gdi32.dll")
|
18
14
|
|
19
15
|
hdc = user32.GetDC(None)
|
20
16
|
|
21
|
-
bgr = gdi32.GetPixel(hdc, x, y)
|
22
|
-
|
23
|
-
r, g, b = bgr.to_bytes(3, "little")
|
24
17
|
|
25
18
|
|
19
|
+
def getrgb(x, y):
|
20
|
+
|
21
|
+
bgr = gdi32.GetPixel(hdc, x, y)
|
22
|
+
|
23
|
+
return bgr.to_bytes(3, "little")
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
r, g, b = getrgb(10, 10)
|
26
28
|
|
27
29
|
print("R={r}, G={g}, B={b}".format(r=r, g=g, b=b))
|
28
30
|
|
2
unpackいらなかった
test
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
```python
|
6
6
|
|
7
7
|
from ctypes import windll
|
8
|
-
|
9
|
-
from struct import unpack
|
10
8
|
|
11
9
|
|
12
10
|
|
1
エンディアンの変更
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
bgr = gdi32.GetPixel(hdc, x, y)
|
24
24
|
|
25
|
-
|
25
|
+
r, g, b = bgr.to_bytes(3, "little")
|
26
26
|
|
27
27
|
|
28
28
|
|