diff --git a/base/MMBitmap.h b/base/MMBitmap.h index bcdec77..31b66cf 100644 --- a/base/MMBitmap.h +++ b/base/MMBitmap.h @@ -5,13 +5,12 @@ #include "types.h" #include "rgb.h" #include -#include - -// #if defined(_MSC_VER) -// #include "ms_stdint.h" -// #else -// #include -// #endif +// #include +#if defined(_MSC_VER) + #include "ms_stdint.h" +#else + #include +#endif #ifdef __cplusplus extern "C" @@ -30,7 +29,7 @@ struct _MMBitmap { typedef struct _MMBitmap MMBitmap; typedef MMBitmap *MMBitmapRef; -MMBitmapRef bitmap; +// MMBitmapRef bitmap; /* Creates new MMBitmap with the given values. * Follows the Create Rule (caller is responsible for destroy()'ing object). */ @@ -62,7 +61,7 @@ MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect); /* Get pointer to pixel of MMBitmapRef. No bounds checking is performed (check * yourself before calling this with MMBitmapPointInBounds(). */ #define MMRGBColorRefAtPoint(image, x, y) \ - (MMRGBColor *)(assert(MMBitmapPointInBounds(bitmap, MMPointMake(x, y))), \ + (MMRGBColor *)(assert(MMBitmapPointInBounds(image, MMPointMake(x, y))), \ ((image)->imageBuffer) + (((image)->bytewidth * (y)) \ + ((x) * (image)->bytesPerPixel))) diff --git a/base/rgb.h b/base/rgb.h index 7a2ef5c..c4269e3 100644 --- a/base/rgb.h +++ b/base/rgb.h @@ -5,7 +5,12 @@ #include /* For abs() */ #include #include "inline_keywords.h" /* For H_INLINE */ -#include +// #include +#if defined(_MSC_VER) + #include "ms_stdint.h" +#else + #include +#endif /* RGB colors in MMBitmaps are stored as BGR for convenience in converting diff --git a/bitmap/bitmap_class.h b/bitmap/bitmap_class.h index ca09930..28f56fd 100644 --- a/bitmap/bitmap_class.h +++ b/bitmap/bitmap_class.h @@ -23,4 +23,4 @@ BitmapObject BitmapObject_FromMMBitmap(MMBitmapRef bitmap); // #endif /* PY_BITMAP_CLASS_H */ //,MMRect rect -MMPoint afindBitmap(MMBitmapRef *needle); \ No newline at end of file +MMPoint aFindBitmap(MMBitmapRef bit_map); \ No newline at end of file diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index 2a96da5..790fd45 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -18,6 +18,26 @@ #include #include +MMPoint aFindBitmap(MMBitmapRef bit_map){ + // ,MMRect rect + MMRect rect; + // rect.size.width=10; + // rect.size.height=20; + // rect.origin.x=10; + // rect.origin.y=20; + + float tolerance = 0.0f; + MMPoint point; + + tolerance=0.5; + + if (findBitmapInRect(bit_map, bit_map, &point, + rect, tolerance) == 0) { + return point; + } + return point; +} + MMBitmapRef aOpenBitmap(char *path){ MMImageType type; diff --git a/robotgo.go b/robotgo.go index cc4f939..fc48633 100644 --- a/robotgo.go +++ b/robotgo.go @@ -222,6 +222,11 @@ func SetKeyboardDelay(x C.size_t) { | |_) | | | | | | | | | / _____ \ | | |______/ |__| |__| |__| |__| /__/ \__\ | _| */ +func FindBitmap(bit C.MMBitmapRef) (C.size_t, C.size_t) { + pos := C.aFindBitmap(bit) + // Println("pos----", pos) + return pos.x, pos.y +} func OpenBitmap(gpath string) C.MMBitmapRef { path := C.CString(gpath) diff --git a/test/main.go b/test/main.go index 7357350..e667d67 100644 --- a/test/main.go +++ b/test/main.go @@ -28,6 +28,9 @@ func arobotgo() { bit_map := robotgo.CaptureScreen(10, 20, 30, 40) Println("...", bit_map) + fx, fy := robotgo.FindBitmap(bit_map) + Println("FindBitmap------", fx, fy) + robotgo.SaveBitmap(bit_map, "test.png", 1) // robotgo.MouseClick()