mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
move FreeBitmap() and ToImage() to screen and optimize code, update godoc
This commit is contained in:
parent
335b3f50a2
commit
617b7b0dc8
49
bitmap.go
49
bitmap.go
@ -26,7 +26,6 @@ package robotgo
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/vcaesar/tt"
|
"github.com/vcaesar/tt"
|
||||||
@ -41,18 +40,13 @@ import (
|
|||||||
|______/ |__| |__| |__| |__| /__/ \__\ | _|
|
|______/ |__| |__| |__| |__| /__/ \__\ | _|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ToBitmap trans C.MMBitmapRef to Bitmap
|
// SaveCapture capture screen and save
|
||||||
func ToBitmap(bit C.MMBitmapRef) Bitmap {
|
func SaveCapture(spath string, args ...int) string {
|
||||||
bitmap := Bitmap{
|
bit := CaptureScreen(args...)
|
||||||
ImgBuf: (*uint8)(bit.imageBuffer),
|
|
||||||
Width: int(bit.width),
|
|
||||||
Height: int(bit.height),
|
|
||||||
Bytewidth: int(bit.bytewidth),
|
|
||||||
BitsPixel: uint8(bit.bitsPerPixel),
|
|
||||||
BytesPerPixel: uint8(bit.bytesPerPixel),
|
|
||||||
}
|
|
||||||
|
|
||||||
return bitmap
|
err := SaveBitmap(bit, spath)
|
||||||
|
FreeBitmap(bit)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToCBitmap trans Bitmap to C.MMBitmapRef
|
// ToCBitmap trans Bitmap to C.MMBitmapRef
|
||||||
@ -69,6 +63,11 @@ func ToCBitmap(bit Bitmap) C.MMBitmapRef {
|
|||||||
return cbitmap
|
return cbitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToMMBitmapRef trans CBitmap to C.MMBitmapRef
|
||||||
|
func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef {
|
||||||
|
return C.MMBitmapRef(bit)
|
||||||
|
}
|
||||||
|
|
||||||
// ToBitmapBytes saves Bitmap to bitmap format in bytes
|
// ToBitmapBytes saves Bitmap to bitmap format in bytes
|
||||||
func ToBitmapBytes(bit C.MMBitmapRef) []byte {
|
func ToBitmapBytes(bit C.MMBitmapRef) []byte {
|
||||||
var len C.size_t
|
var len C.size_t
|
||||||
@ -82,11 +81,6 @@ func ToBitmapBytes(bit C.MMBitmapRef) []byte {
|
|||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToMMBitmapRef trans CBitmap to C.MMBitmapRef
|
|
||||||
func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef {
|
|
||||||
return C.MMBitmapRef(bit)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TostringBitmap tostring bitmap to string
|
// TostringBitmap tostring bitmap to string
|
||||||
func TostringBitmap(bit C.MMBitmapRef) string {
|
func TostringBitmap(bit C.MMBitmapRef) string {
|
||||||
strBit := C.tostring_bitmap(bit)
|
strBit := C.tostring_bitmap(bit)
|
||||||
@ -99,17 +93,6 @@ func TocharBitmap(bit C.MMBitmapRef) *C.char {
|
|||||||
return strBit
|
return strBit
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToImage convert C.MMBitmapRef to standard image.Image
|
|
||||||
func ToImage(bit C.MMBitmapRef) image.Image {
|
|
||||||
return ToRGBA(bit)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToRGBA convert C.MMBitmapRef to standard image.RGBA
|
|
||||||
func ToRGBA(bit C.MMBitmapRef) *image.RGBA {
|
|
||||||
bmp1 := ToBitmap(bit)
|
|
||||||
return ToRGBAGo(bmp1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func internalFindBitmap(bit, sbit C.MMBitmapRef, tolerance float64) (int, int) {
|
func internalFindBitmap(bit, sbit C.MMBitmapRef, tolerance float64) (int, int) {
|
||||||
pos := C.find_bitmap(bit, sbit, C.float(tolerance))
|
pos := C.find_bitmap(bit, sbit, C.float(tolerance))
|
||||||
// fmt.Println("pos----", pos)
|
// fmt.Println("pos----", pos)
|
||||||
@ -337,7 +320,7 @@ func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef {
|
|||||||
// Convert convert the bitmap
|
// Convert convert the bitmap
|
||||||
//
|
//
|
||||||
// robotgo.Convert(opath, spath string, type int)
|
// robotgo.Convert(opath, spath string, type int)
|
||||||
func Convert(opath, spath string, args ...int) {
|
func Convert(opath, spath string, args ...int) string {
|
||||||
var mtype = 1
|
var mtype = 1
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
mtype = args[0]
|
mtype = args[0]
|
||||||
@ -346,13 +329,7 @@ func Convert(opath, spath string, args ...int) {
|
|||||||
// C.CString()
|
// C.CString()
|
||||||
bitmap := OpenBitmap(opath)
|
bitmap := OpenBitmap(opath)
|
||||||
// fmt.Println("a----", bit_map)
|
// fmt.Println("a----", bit_map)
|
||||||
SaveBitmap(bitmap, spath, mtype)
|
return SaveBitmap(bitmap, spath, mtype)
|
||||||
}
|
|
||||||
|
|
||||||
// FreeBitmap free and dealloc the C bitmap
|
|
||||||
func FreeBitmap(bitmap C.MMBitmapRef) {
|
|
||||||
// C.destroyMMBitmap(bitmap)
|
|
||||||
C.bitmap_dealloc(bitmap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FreeBitmapArr free and dealloc the C bitmap array
|
// FreeBitmapArr free and dealloc the C bitmap array
|
||||||
|
@ -26,12 +26,12 @@ bool bitmap_ready(MMBitmapRef bitmap){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmap_dealloc(MMBitmapRef bitmap){
|
// void bitmap_dealloc(MMBitmapRef bitmap){
|
||||||
if (bitmap != NULL) {
|
// if (bitmap != NULL) {
|
||||||
destroyMMBitmap(bitmap);
|
// destroyMMBitmap(bitmap);
|
||||||
bitmap = NULL;
|
// bitmap = NULL;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool bitmap_copy_to_pboard(MMBitmapRef bitmap){
|
bool bitmap_copy_to_pboard(MMBitmapRef bitmap){
|
||||||
MMPasteError err;
|
MMPasteError err;
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func colorPicker() {
|
func colorPicker() {
|
||||||
|
// click the left mouse button to get the value
|
||||||
m := robotgo.AddEvent("mleft")
|
m := robotgo.AddEvent("mleft")
|
||||||
if m {
|
if m {
|
||||||
x, y := robotgo.GetMousePos()
|
x, y := robotgo.GetMousePos()
|
||||||
|
33
robotgo.go
33
robotgo.go
@ -371,12 +371,35 @@ func CaptureImg(args ...int) image.Image {
|
|||||||
return ToImage(bit)
|
return ToImage(bit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveCapture capture screen and save
|
// FreeBitmap free and dealloc the C bitmap
|
||||||
func SaveCapture(spath string, args ...int) {
|
func FreeBitmap(bitmap C.MMBitmapRef) {
|
||||||
bit := CaptureScreen(args...)
|
// C.destroyMMBitmap(bitmap)
|
||||||
|
C.bitmap_dealloc(bitmap)
|
||||||
|
}
|
||||||
|
|
||||||
SaveBitmap(bit, spath)
|
// ToBitmap trans C.MMBitmapRef to Bitmap
|
||||||
FreeBitmap(bit)
|
func ToBitmap(bit C.MMBitmapRef) Bitmap {
|
||||||
|
bitmap := Bitmap{
|
||||||
|
ImgBuf: (*uint8)(bit.imageBuffer),
|
||||||
|
Width: int(bit.width),
|
||||||
|
Height: int(bit.height),
|
||||||
|
Bytewidth: int(bit.bytewidth),
|
||||||
|
BitsPixel: uint8(bit.bitsPerPixel),
|
||||||
|
BytesPerPixel: uint8(bit.bytesPerPixel),
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToImage convert C.MMBitmapRef to standard image.Image
|
||||||
|
func ToImage(bit C.MMBitmapRef) image.Image {
|
||||||
|
return ToRGBA(bit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToRGBA convert C.MMBitmapRef to standard image.RGBA
|
||||||
|
func ToRGBA(bit C.MMBitmapRef) *image.RGBA {
|
||||||
|
bmp1 := ToBitmap(bit)
|
||||||
|
return ToRGBAGo(bmp1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -95,6 +95,13 @@ char* get_XDisplay_name(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bitmap_dealloc(MMBitmapRef bitmap){
|
||||||
|
if (bitmap != NULL) {
|
||||||
|
destroyMMBitmap(bitmap);
|
||||||
|
bitmap = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// capture_screen capture screen
|
// capture_screen capture screen
|
||||||
MMBitmapRef capture_screen(int32_t x, int32_t y, int32_t w, int32_t h){
|
MMBitmapRef capture_screen(int32_t x, int32_t y, int32_t w, int32_t h){
|
||||||
// if () {
|
// if () {
|
||||||
|
Loading…
Reference in New Issue
Block a user