Exemple #1
0
// ScreenShot takes a screenshot and returns it in jpeg format with given
// quality. This is not threadsafe.
func ScreenShot(quality float64) ([]byte, error) {
	C.JPEG(C.float(quality))
	data := (*[1 << 30]byte)(unsafe.Pointer(C.Data()))[0:C.Length()]
	newData := make([]byte, C.Length())
	copy(newData, data)
	C.Free()
	return newData, nil
}
Exemple #2
0
func Raw() (data []byte, width, height, stride int, err error) {
	C.Raw()
	// data = (*[1 << 30]byte)(unsafe.Pointer(C.Data()))[0:C.Length()]
	// newData := make([]byte, C.Length())
	// copy(newData, data)
	// C.Free()
	// return newData, int(C.width), int(C.height), int(C.stride), nil
	data = (*[1 << 30]byte)(unsafe.Pointer(C.Data()))[0:C.Length()]
	return data, int(C.width), int(C.height), int(C.stride), nil
}
// Screenshot returns an image.Image object containing the current screenshot.
func Screenshot() image.Image {
	C.Raw()
	defer C.Clean()

	data := (*[1 << 30]byte)(unsafe.Pointer(C.Data()))[0:C.Length()]
	width := int(C.width)
	height := int(C.height)
	stride := int(C.stride)
	return ConvertMacBGRAToRGBA(width, height, stride, data)
}