rename BCaptureScreen and update code

This commit is contained in:
vcaesar 2017-11-09 22:40:58 +08:00
parent f112ab1abc
commit 7dfebac8b9
3 changed files with 87 additions and 8 deletions

View File

@ -142,12 +142,51 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
h = displaySize.height h = displaySize.height
}) })
bit := C.aCaptureScreen(x, y, w, h) bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit.width) // fmt.Println("...", bit.width)
return bit return bit
} }
// BCaptureScreen capture the screen and return bitmap(go struct) // GoCaptureScreen capture the screen and return bitmap(go struct)
func GoCaptureScreen(args ...int) Bitmap {
var (
x C.size_t
y C.size_t
w C.size_t
h C.size_t
)
Try(func() {
x = C.size_t(args[0])
y = C.size_t(args[1])
w = C.size_t(args[2])
h = C.size_t(args[3])
}, func(e interface{}) {
// fmt.Println("err:::", e)
x = 0
y = 0
//Get screen size.
var displaySize C.MMSize
displaySize = C.getMainDisplaySize()
w = displaySize.width
h = displaySize.height
})
bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit)
bitmap := Bitmap{
ImageBuffer: (*uint8)(bit.imageBuffer),
Width: int(bit.width),
Height: int(bit.height),
Bytewidth: int(bit.bytewidth),
BitsPerPixel: uint8(bit.bitsPerPixel),
BytesPerPixel: uint8(bit.bytesPerPixel),
}
return bitmap
}
// BCaptureScreen capture the screen and return bitmap(go struct), Wno-deprecated
func BCaptureScreen(args ...int) Bitmap { func BCaptureScreen(args ...int) Bitmap {
var ( var (
x C.size_t x C.size_t
@ -172,7 +211,7 @@ func BCaptureScreen(args ...int) Bitmap {
h = displaySize.height h = displaySize.height
}) })
bit := C.aCaptureScreen(x, y, w, h) bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit) // fmt.Println("...", bit)
bitmap := Bitmap{ bitmap := Bitmap{
ImageBuffer: (*uint8)(bit.imageBuffer), ImageBuffer: (*uint8)(bit.imageBuffer),

View File

@ -142,12 +142,51 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
h = displaySize.height h = displaySize.height
}) })
bit := C.aCaptureScreen(x, y, w, h) bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit.width) // fmt.Println("...", bit.width)
return bit return bit
} }
// BCaptureScreen capture the screen and return bitmap(go struct) // GoCaptureScreen capture the screen and return bitmap(go struct)
func GoCaptureScreen(args ...int) Bitmap {
var (
x C.size_t
y C.size_t
w C.size_t
h C.size_t
)
Try(func() {
x = C.size_t(args[0])
y = C.size_t(args[1])
w = C.size_t(args[2])
h = C.size_t(args[3])
}, func(e interface{}) {
// fmt.Println("err:::", e)
x = 0
y = 0
//Get screen size.
var displaySize C.MMSize
displaySize = C.getMainDisplaySize()
w = displaySize.width
h = displaySize.height
})
bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit)
bitmap := Bitmap{
ImageBuffer: (*uint8)(bit.imageBuffer),
Width: int(bit.width),
Height: int(bit.height),
Bytewidth: int(bit.bytewidth),
BitsPerPixel: uint8(bit.bitsPerPixel),
BytesPerPixel: uint8(bit.bytesPerPixel),
}
return bitmap
}
// BCaptureScreen capture the screen and return bitmap(go struct), Wno-deprecated
func BCaptureScreen(args ...int) Bitmap { func BCaptureScreen(args ...int) Bitmap {
var ( var (
x C.size_t x C.size_t
@ -172,7 +211,7 @@ func BCaptureScreen(args ...int) Bitmap {
h = displaySize.height h = displaySize.height
}) })
bit := C.aCaptureScreen(x, y, w, h) bit := C.capture_screen(x, y, w, h)
// fmt.Println("...", bit) // fmt.Println("...", bit)
bitmap := Bitmap{ bitmap := Bitmap{
ImageBuffer: (*uint8)(bit.imageBuffer), ImageBuffer: (*uint8)(bit.imageBuffer),
@ -637,7 +676,7 @@ func FindEveryBitmap(args ...interface{}) (int, int) {
return int(pos.x), int(pos.y) return int(pos.x), int(pos.y)
} }
// FindBit find the bitmap // FindBit find the bitmap, Wno-deprecated
func FindBit(args ...interface{}) (int, int) { func FindBit(args ...interface{}) (int, int) {
var bit C.MMBitmapRef var bit C.MMBitmapRef
bit = args[0].(C.MMBitmapRef) bit = args[0].(C.MMBitmapRef)

View File

@ -77,7 +77,8 @@ char* aGetXDisplayName(){
#endif #endif
} }
MMBitmapRef aCaptureScreen(size_t x, size_t y, size_t w, size_t h){ // capture_screen aCaptureScreen
MMBitmapRef capture_screen(size_t x, size_t y, size_t w, size_t h){
// if (){ // if (){
// x = 0; // x = 0;
// y = 0; // y = 0;