optimize bitmap code

This commit is contained in:
vcaesar 2018-05-30 23:52:09 +08:00
parent dd31f29ad5
commit 52a7bb04d0

View File

@ -834,23 +834,20 @@ func internalFindBitmap(bit, sbit C.MMBitmapRef, tolerance float64) (int, int) {
// //
// robotgo.FindBitmap(bitmap, subbitamp C.MMBitmapRef, tolerance float64) // robotgo.FindBitmap(bitmap, subbitamp C.MMBitmapRef, tolerance float64)
// //
func FindBitmap(args ...interface{}) (int, int) { func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
var ( var (
bit C.MMBitmapRef
sbit C.MMBitmapRef sbit C.MMBitmapRef
tolerance float64 tolerance float64
) )
bit = args[0].(C.MMBitmapRef) if len(args) > 0 {
sbit = args[0].(C.MMBitmapRef)
if len(args) > 1 {
sbit = args[1].(C.MMBitmapRef)
} else { } else {
sbit = CaptureScreen() sbit = CaptureScreen()
} }
if len(args) > 2 { if len(args) > 1 {
tolerance = args[2].(float64) tolerance = args[1].(float64)
} else { } else {
tolerance = 0.5 tolerance = 0.5
} }
@ -981,12 +978,12 @@ func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool {
} }
// OpenBitmap open the bitmap return C.MMBitmapRef // OpenBitmap open the bitmap return C.MMBitmapRef
func OpenBitmap(gpath string, args ...interface{}) C.MMBitmapRef { func OpenBitmap(gpath string, args ...int) C.MMBitmapRef {
path := C.CString(gpath) path := C.CString(gpath)
var mtype C.uint16_t = 1 var mtype C.uint16_t = 1
if len(args) > 0 { if len(args) > 0 {
mtype = C.uint16_t(args[0].(int)) mtype = C.uint16_t(args[0])
} }
bit := C.bitmap_open(path, mtype) bit := C.bitmap_open(path, mtype)
@ -1017,10 +1014,10 @@ func BitmapStr(str string) C.MMBitmapRef {
// SaveBitmap save the bitmap to image // SaveBitmap save the bitmap to image
// robotgo.SaveBimap(bitmap C.MMBitmapRef, path string, type int) // robotgo.SaveBimap(bitmap C.MMBitmapRef, path string, type int)
func SaveBitmap(bitmap C.MMBitmapRef, gpath string, args ...interface{}) string { func SaveBitmap(bitmap C.MMBitmapRef, gpath string, args ...int) string {
var mtype C.uint16_t = 1 var mtype C.uint16_t = 1
if len(args) > 0 { if len(args) > 0 {
mtype = C.uint16_t(args[0].(int)) mtype = C.uint16_t(args[0])
} }
path := C.CString(gpath) path := C.CString(gpath)
@ -1053,18 +1050,13 @@ func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef {
} }
// Convert convert bitmap // Convert convert bitmap
func Convert(args ...interface{}) { func Convert(opath, spath string, args ...int) {
var mtype int var mtype = 1
Try(func() { if len(args) > 0 {
mtype = args[2].(int) mtype = args[0]
}, func(e interface{}) { }
// fmt.Println("err:::", e)
mtype = 1
})
// C.CString() // C.CString()
opath := args[0].(string)
spath := args[1].(string)
bitmap := OpenBitmap(opath) bitmap := OpenBitmap(opath)
// fmt.Println("a----", bit_map) // fmt.Println("a----", bit_map)
SaveBitmap(bitmap, spath, mtype) SaveBitmap(bitmap, spath, mtype)