mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 06:33:56 +00:00
add func ToImage: convert C.MMBitmapRef to standard image.Image
This commit is contained in:
parent
fb2d6f2720
commit
fe3b4b3331
26
robotgo.go
26
robotgo.go
@ -1542,3 +1542,29 @@ func ActiveName(name string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ToImage convert C.MMBitmapRef to standard image.Image
|
||||
func ToImage(bit C.MMBitmapRef) image.Image {
|
||||
bmp1 := ToBitmap(bit)
|
||||
img1 := image.NewRGBA(image.Rect(0, 0, bmp1.Width, bmp1.Height))
|
||||
img1.Pix = make([]uint8, bmp1.Bytewidth*bmp1.Height)
|
||||
copyToVUint8A(img1.Pix, bmp1.ImgBuf)
|
||||
img1.Stride = bmp1.Bytewidth
|
||||
return img1
|
||||
}
|
||||
|
||||
func val(p *uint8, n int) uint8 {
|
||||
addr := uintptr(unsafe.Pointer(p))
|
||||
addr += uintptr(n)
|
||||
p1 := (*uint8)(unsafe.Pointer(addr))
|
||||
return *p1
|
||||
}
|
||||
|
||||
func copyToVUint8A(dst []uint8, src *uint8) {
|
||||
for i := 0; i < len(dst)-4; i += 4 {
|
||||
dst[i] = val(src, i+2)
|
||||
dst[i+1] = val(src, i+1)
|
||||
dst[i+2] = val(src, i)
|
||||
dst[i+3] = val(src, i+3)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user