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