mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
add ToBitmapBytes func (#204)
This commit is contained in:
parent
19c54fff4f
commit
d280b98394
@ -320,6 +320,16 @@ int saveMMBitmapAsBMP(MMBitmapRef bitmap, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *saveMMBitmapAsBytes(MMBitmapRef bitmap, size_t *dataLen)
|
||||
{
|
||||
uint8_t *data;
|
||||
if ((data = createBitmapData(bitmap, dataLen)) == NULL) {
|
||||
*dataLen = -1;
|
||||
return NULL;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static uint8_t *readImageData(FILE *fp, size_t width, size_t height,
|
||||
uint8_t bytesPerPixel, size_t bytewidth)
|
||||
{
|
||||
|
13
robotgo.go
13
robotgo.go
@ -797,6 +797,19 @@ func ToCBitmap(bit Bitmap) C.MMBitmapRef {
|
||||
return cbitmap
|
||||
}
|
||||
|
||||
// ToBitmapBytes saves Bitmap to bitmap format in bytes
|
||||
func ToBitmapBytes(bit C.MMBitmapRef) []byte {
|
||||
var len C.size_t
|
||||
ptr := C.saveMMBitmapAsBytes(bit, &len)
|
||||
if int(len) < 0 {
|
||||
return nil
|
||||
}
|
||||
bs := C.GoBytes(unsafe.Pointer(ptr), C.int(len))
|
||||
C.free(unsafe.Pointer(ptr))
|
||||
return bs
|
||||
}
|
||||
|
||||
|
||||
// ToMMBitmapRef trans CBitmap to C.MMBitmapRef
|
||||
func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef {
|
||||
return C.MMBitmapRef(bit)
|
||||
|
Loading…
Reference in New Issue
Block a user