Skip to content

Commit e4bb647

Browse files
committed
Add GetPixel + SetPixel, fixes lxn#22
1 parent 8032d70 commit e4bb647

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

gdi32.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ var (
982982
getEnhMetaFile uintptr
983983
getEnhMetaFileHeader uintptr
984984
getObject uintptr
985+
getPixel uintptr
985986
getStockObject uintptr
986987
getTextExtentExPoint uintptr
987988
getTextExtentPoint32 uintptr
@@ -995,6 +996,7 @@ var (
995996
selectObject uintptr
996997
setBkMode uintptr
997998
setBrushOrgEx uintptr
999+
setPixel uintptr
9981000
setPixelFormat uintptr
9991001
setStretchBltMode uintptr
10001002
setTextColor uintptr
@@ -1035,6 +1037,7 @@ func init() {
10351037
getEnhMetaFile = MustGetProcAddress(libgdi32, "GetEnhMetaFileW")
10361038
getEnhMetaFileHeader = MustGetProcAddress(libgdi32, "GetEnhMetaFileHeader")
10371039
getObject = MustGetProcAddress(libgdi32, "GetObjectW")
1040+
getPixel = MustGetProcAddress(libgdi32, "GetPixel")
10381041
getStockObject = MustGetProcAddress(libgdi32, "GetStockObject")
10391042
getTextExtentExPoint = MustGetProcAddress(libgdi32, "GetTextExtentExPointW")
10401043
getTextExtentPoint32 = MustGetProcAddress(libgdi32, "GetTextExtentPoint32W")
@@ -1049,6 +1052,7 @@ func init() {
10491052
selectObject = MustGetProcAddress(libgdi32, "SelectObject")
10501053
setBkMode = MustGetProcAddress(libgdi32, "SetBkMode")
10511054
setBrushOrgEx = MustGetProcAddress(libgdi32, "SetBrushOrgEx")
1055+
setPixel = MustGetProcAddress(libgdi32, "SetPixel")
10521056
setPixelFormat = MustGetProcAddress(libgdi32, "SetPixelFormat")
10531057
setStretchBltMode = MustGetProcAddress(libgdi32, "SetStretchBltMode")
10541058
setTextColor = MustGetProcAddress(libgdi32, "SetTextColor")
@@ -1303,6 +1307,15 @@ func GetObject(hgdiobj HGDIOBJ, cbBuffer uintptr, lpvObject unsafe.Pointer) int3
13031307
return int32(ret)
13041308
}
13051309

1310+
func GetPixel(hdc HDC, nXPos, nYPos int32) COLORREF {
1311+
ret, _, _ := syscall.Syscall(getPixel, 3,
1312+
uintptr(hdc),
1313+
uintptr(nXPos),
1314+
uintptr(nYPos))
1315+
1316+
return COLORREF(ret)
1317+
}
1318+
13061319
func GetStockObject(fnObject int32) HGDIOBJ {
13071320
ret, _, _ := syscall.Syscall(getDeviceCaps, 1,
13081321
uintptr(fnObject),
@@ -1445,6 +1458,18 @@ func SetBrushOrgEx(hdc HDC, nXOrg, nYOrg int32, lppt *POINT) bool {
14451458
return ret != 0
14461459
}
14471460

1461+
func SetPixel(hdc HDC, X, Y int32, crColor COLORREF) COLORREF {
1462+
ret, _, _ := syscall.Syscall6(setPixel, 4,
1463+
uintptr(hdc),
1464+
uintptr(X),
1465+
uintptr(Y),
1466+
uintptr(crColor),
1467+
0,
1468+
0)
1469+
1470+
return COLORREF(ret)
1471+
}
1472+
14481473
func SetPixelFormat(hdc HDC, iPixelFormat int32, ppfd *PIXELFORMATDESCRIPTOR) bool {
14491474
ret, _, _ := syscall.Syscall(setPixelFormat, 3,
14501475
uintptr(hdc),

0 commit comments

Comments
 (0)