From b8e7e584a7910c3296882a118dcd059e37676eb6 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 28 Oct 2017 21:41:20 +0800 Subject: [PATCH] add bitmap string func --- bitmap/goBitmap.h | 13 +++++++++++++ robotgo.go | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index 3fa3264..5597e1a 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -108,6 +108,19 @@ MMBitmapRef bitmap_open(char *path, uint16_t ttype){ } +MMBitmapRef bitmap_from_string(const char *str){ + size_t len = strlen(str); + + MMBitmapRef bitmap; + MMBMPStringError err; + + if ((bitmap = createMMBitmapFromString((unsigned char*)str, len, &err)) == NULL) { + return NULL; + } + + return bitmap; +} + char *bitmap_save(MMBitmapRef bitmap, char *path, uint16_t type){ if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) { return "Could not save image to file."; diff --git a/robotgo.go b/robotgo.go index bad7185..3bbde2a 100644 --- a/robotgo.go +++ b/robotgo.go @@ -55,7 +55,7 @@ import ( ) const ( - version string = "v0.46.0.400, Pyrenees Mountains!" + version string = "v0.46.0.401, Pyrenees Mountains!" ) // GetVersion get version @@ -638,6 +638,14 @@ func OpenBitmap(args ...interface{}) C.MMBitmapRef { // defer C.free(unsafe.Pointer(path)) } +// BitmapStr bitmap from string +func BitmapStr(str string) C.MMBitmapRef { + cs := C.CString(str) + bit := C.bitmap_from_string(cs) + defer C.free(unsafe.Pointer(cs)) + return bit +} + // SaveBitmap save the bitmap func SaveBitmap(args ...interface{}) string { var mtype C.uint16_t