objective-c – 不显示鼠标光标

objective-c – 不显示鼠标光标,第1张

概述我正在开发Mac桌面应用程序,我正在使用它捕获屏幕 CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault); 并显示屏幕截图, 问题是,我希望它也应该显示鼠标光标,但它没有显示, 我需要为此启用任何设 我正在开发Mac桌面应用程序,我正在使用它捕获屏幕

CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite,kCGWindowListOptionAll,kCGNullWindowID,kCGWindowImageDefault);

并显示屏幕截图,
问题是,我希望它也应该显示鼠标光标,但它没有显示,
我需要为此启用任何设置吗?

我在调用此函数之前尝试了以下 *** 作

CGdisplayShowCursor(kCGDirectMaindisplay);CGAssociateMouseAndMouseCursorposition(true);

但它不起作用,
当我检查使用以下

bool bCursor = CGCursorIsDrawnInFramebuffer(); /* This returns false */bCursor = CGCursorIsVisible();  /* This returns true */

这个值说,游标没有在framebuffer()中绘制,但是光标是可见的,
我想只有我需要做的是,在帧缓冲区中绘制光标,但这是怎样的挑战,

提前致谢.

解决方法 看来,framebuffer没有给我鼠标光标,所以我正在绘制自己的,这是代码片段,可能对你们有帮助,

-(CGImageRef)appendMouseCursor:(CGImageRef)pSourceImage{    // get the cursor image     NSPoint mouseLoc;     mouseLoc = [NSEvent mouseLocation]; //get cur    NSLog(@"Mouse location is x=%d,y=%d",(int)mouseLoc.x,(int)mouseLoc.y);    // get the mouse image     NSImage *overlay    =   [[[NSCursor arrowCursor] image] copy];    NSLog(@"Mouse location is x=%d,y=%d cursor wIDth = %d,cursor height = %d",(int)mouseLoc.y,(int)[overlay size].wIDth,(int)[overlay size].height);    int x = (int)mouseLoc.x;    int y = (int)mouseLoc.y;    int w = (int)[overlay size].wIDth;    int h = (int)[overlay size].height;    int org_x = x;    int org_y = y;    size_t height = CGImageGetHeight(pSourceImage);    size_t wIDth =  CGImageGetWIDth(pSourceImage);    int bytesPerRow = CGImageGetBytesPerRow(pSourceImage);    unsigned int * imgData = (unsigned int*)malloc(height*bytesPerRow);    // have the graphics context Now,CGRect bgBoundingBox = CGRectMake (0,wIDth,height);    CGContextRef context =  CGBitmapContextCreate(imgData,height,8,// 8 bits per component                                                   bytesPerRow,CGImageGetcolorSpace(pSourceImage),CGImageGetBitmAPInfo(pSourceImage));    // first draw the image     CGContextDrawImage(context,bgBoundingBox,pSourceImage);    // then mouse cursor     CGContextDrawImage(context,CGRectMake(0,height),CGRectMake(org_x,org_y,w,h),[overlay CGImageForProposedRect: NulL context: NulL hints: NulL] );    // assuming both the image has been drawn then create an Image Ref for that     CGImageRef pFinalimage = CGBitmapContextCreateImage(context);    CGContextRelease(context);    return pFinalimage; /* to be released by the caller */}
总结

以上是内存溢出为你收集整理的objective-c – 不显示鼠标光标全部内容,希望文章能够帮你解决objective-c – 不显示鼠标光标所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存