不显示鼠标光标 [英] Not displaying Mouse cursor

查看:881
本文介绍了不显示鼠标光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Mac桌面应用程序,其中我捕获屏幕使用

I am developing Mac desktop application, where i am capturing the screen using

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

并显示屏幕截图,
问题是,我期望它应该显示鼠标光标,但它不显示,
我需要启用任何设置吗?

and display the screen shot, The problem is, i am expecting it should show the mouse cursor too, but its not showing, do i need to enable any settings for that ?

我在调用此函数之前尝试过以下操作。

I tried following before calling this function

CGDisplayShowCursor(kCGDirectMainDisplay);

CGAssociateMouseAndMouseCursorPosition(true);

但它不工作,
当我使用下面的

but it didn't work, When i checked using following

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

bCursor = CGCursorIsVisible();  /* This returns true */



这个值说,光标不是在framebuffer游标是可见的,
我想只有我需要做的是,在framebuffer中绘制光标,但是如何是挑战,

This values says, cursor was not drawn in the framebuffer ( ) but cursor is visible, I suppose only i need to do is, Draw cursor in the framebuffer, but how that is the challenge,

提前感谢。

推荐答案

看起来,framebuffer不给我鼠标光标,所以我画自己的,这是代码片段

it seems, framebuffer doesn't give me the mouse cursor, so i am drawing my own, this is the code snippet , might be help full to you guys,

-(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.x,(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, 0, width,height);

    CGContextRef context =  CGBitmapContextCreate(imgData, width, 
                                                  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, 0, width,height),pSourceImage);

    // then mouse cursor 
    CGContextDrawImage(context,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 */
}

这篇关于不显示鼠标光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆