mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Merge pull request #334 from go-vgo/bitmap-pr
add byte to image function and fixed #333
This commit is contained in:
commit
fe5f2231fc
19
robotgo.go
19
robotgo.go
@ -49,6 +49,7 @@ package robotgo
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
|
||||
@ -977,7 +978,7 @@ func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
|
||||
|
||||
fx, fy := internalFindBitmap(bit, sbit, tolerance)
|
||||
// FreeBitmap(bit)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(sbit)
|
||||
}
|
||||
|
||||
@ -1010,7 +1011,7 @@ func FindPic(path string, args ...interface{}) (int, int) {
|
||||
|
||||
fx, fy := internalFindBitmap(openbit, sbit, tolerance)
|
||||
FreeBitmap(openbit)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(sbit)
|
||||
}
|
||||
|
||||
@ -1055,7 +1056,7 @@ func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (posArr []MPoint) {
|
||||
|
||||
pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos)
|
||||
// FreeBitmap(bit)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(sbit)
|
||||
}
|
||||
if pos == nil {
|
||||
@ -1126,6 +1127,12 @@ func DecodeImg(path string) (image.Image, string, error) {
|
||||
return imgo.DecodeFile(path)
|
||||
}
|
||||
|
||||
// ByteToImg convert []byte to image.Image
|
||||
func ByteToImg(b []byte) (image.Image, error) {
|
||||
img, _, err := image.Decode(bytes.NewReader(b))
|
||||
return img, err
|
||||
}
|
||||
|
||||
// ToImage convert C.MMBitmapRef to standard image.Image
|
||||
func ToImage(bit C.MMBitmapRef) image.Image {
|
||||
bmp1 := ToBitmap(bit)
|
||||
@ -1292,7 +1299,7 @@ func FindColor(color CHex, args ...interface{}) (int, int) {
|
||||
}
|
||||
|
||||
pos := C.bitmap_find_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(bitmap)
|
||||
}
|
||||
|
||||
@ -1349,7 +1356,7 @@ func FindEveryColor(color CHex, args ...interface{}) (posArr []MPoint) {
|
||||
}
|
||||
|
||||
pos := C.bitmap_find_every_color(bitmap, C.MMRGBHex(color), tolerance, &lpos)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(bitmap)
|
||||
}
|
||||
|
||||
@ -1389,7 +1396,7 @@ func CountColor(color CHex, args ...interface{}) int {
|
||||
}
|
||||
|
||||
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||
if len(args) <= 0 {
|
||||
if len(args) <= 0 || (len(args) > 0 && args[0] == nil) {
|
||||
FreeBitmap(bitmap)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user