mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
update screen code
This commit is contained in:
parent
0c262d4d42
commit
ad5a1aa7ca
@ -27,10 +27,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){
|
||||
CGDirectDisplayID displayID = CGMainDisplayID();
|
||||
|
||||
CGImageRef image = CGDisplayCreateImageForRect(displayID,
|
||||
CGRectMake(rect.origin.x,
|
||||
rect.origin.y,
|
||||
rect.size.w,
|
||||
rect.size.h));
|
||||
CGRectMake(rect.origin.x, rect.origin.y, rect.size.w, rect.size.h));
|
||||
|
||||
if (!image) { return NULL; }
|
||||
|
||||
@ -43,15 +40,12 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){
|
||||
|
||||
CFDataGetBytes(imageData, CFRangeMake(0, bufferSize), buffer);
|
||||
|
||||
bitmap = createMMBitmap(buffer,
|
||||
CGImageGetWidth(image),
|
||||
CGImageGetHeight(image),
|
||||
CGImageGetBytesPerRow(image),
|
||||
CGImageGetBitsPerPixel(image),
|
||||
bitmap = createMMBitmap(buffer,
|
||||
CGImageGetWidth(image),CGImageGetHeight(image),
|
||||
CGImageGetBytesPerRow(image), CGImageGetBitsPerPixel(image),
|
||||
CGImageGetBitsPerPixel(image) / 8);
|
||||
|
||||
CFRelease(imageData);
|
||||
|
||||
CGImageRelease(image);
|
||||
|
||||
return bitmap;
|
||||
@ -59,22 +53,16 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){
|
||||
MMBitmapRef bitmap;
|
||||
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
XImage *image = XGetImage(display,
|
||||
XDefaultRootWindow(display),
|
||||
(int)rect.origin.x,
|
||||
(int)rect.origin.y,
|
||||
(unsigned int)rect.size.w,
|
||||
(unsigned int)rect.size.h,
|
||||
AllPlanes, ZPixmap);
|
||||
XImage *image = XGetImage(display, XDefaultRootWindow(display),
|
||||
(int)rect.origin.x, (int)rect.origin.y,
|
||||
(unsigned int)rect.size.w,(unsigned int)rect.size.h,
|
||||
AllPlanes, ZPixmap);
|
||||
XCloseDisplay(display);
|
||||
if (image == NULL) return NULL;
|
||||
if (image == NULL) { return NULL; }
|
||||
|
||||
bitmap = createMMBitmap((uint8_t *)image->data,
|
||||
rect.size.w,
|
||||
rect.size.h,
|
||||
(size_t)image->bytes_per_line,
|
||||
(uint8_t)image->bits_per_pixel,
|
||||
(uint8_t)image->bits_per_pixel / 8);
|
||||
bitmap = createMMBitmap((uint8_t *)image->data,
|
||||
rect.size.w, rect.size.h, (size_t)image->bytes_per_line,
|
||||
(uint8_t)image->bits_per_pixel, (uint8_t)image->bits_per_pixel / 8);
|
||||
image->data = NULL; /* Steal ownership of bitmap data so we don't have to
|
||||
* copy it. */
|
||||
XDestroyImage(image);
|
||||
@ -101,7 +89,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){
|
||||
bi.bmiHeader.biClrImportant = 0;
|
||||
|
||||
screen = GetDC(NULL); /* Get entire screen */
|
||||
if (screen == NULL) return NULL;
|
||||
if (screen == NULL) { return NULL; }
|
||||
|
||||
/* Get screen data in display device context. */
|
||||
dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &data, NULL, 0);
|
||||
@ -109,30 +97,20 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){
|
||||
/* Copy the data into a bitmap struct. */
|
||||
if ((screenMem = CreateCompatibleDC(screen)) == NULL ||
|
||||
SelectObject(screenMem, dib) == NULL ||
|
||||
!BitBlt(screenMem,
|
||||
(int)0,
|
||||
(int)0,
|
||||
(int)rect.size.w,
|
||||
(int)rect.size.h,
|
||||
screen,
|
||||
rect.origin.x,
|
||||
rect.origin.y,
|
||||
SRCCOPY)) {
|
||||
!BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h,
|
||||
screen, rect.origin.x, rect.origin.y, SRCCOPY)
|
||||
) {
|
||||
|
||||
/* Error copying data. */
|
||||
ReleaseDC(NULL, screen);
|
||||
DeleteObject(dib);
|
||||
if (screenMem != NULL) DeleteDC(screenMem);
|
||||
if (screenMem != NULL) { DeleteDC(screenMem); }
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bitmap = createMMBitmap(NULL,
|
||||
rect.size.w,
|
||||
rect.size.h,
|
||||
4 * rect.size.w,
|
||||
(uint8_t)bi.bmiHeader.biBitCount,
|
||||
4);
|
||||
bitmap = createMMBitmap(NULL, rect.size.w, rect.size.h, 4 * rect.size.w,
|
||||
(uint8_t)bi.bmiHeader.biBitCount, 4);
|
||||
|
||||
/* Copy the data to our pixel buffer. */
|
||||
if (bitmap != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user