我想开发一个守护进程,它将在登录前的会话中捕获我的OSX的屏幕
我尝试使用Quazt显示服务(流)和核心图形框架,但它仍然不可用
我的代码使用Quartz服务
m_isExit = FALSE;
m_display = kCGDirectMainDisplay; // 1
m_displayMode = CGDisplayCopyDisplayMode(m_display);
if (m_display == NULL)
{
throw Exception("OSX-Quart service Can not get Display mode ",VF_ERR_SCREEN_MONITOR_OSX_QUART_CREATE);
}
m_height = CGDisplayModeGetHeight(m_displayMode);
m_width = CGDisplayModeGetWidth(m_displayMode);
m_stream = CGDisplayStreamCreate(m_display,m_width,m_height,'BGRA',NULL,VncStreamFrameAvailableHandler);
if (m_stream == NULL)
{
throw Exception("OSX-Quart service Can not create Stream",VF_ERR_SCREEN_MONITOR_OSX_QUART_CREATE);
}
m_screenMonitorThread.start(*this);
它总是通过例外。 另一个使用Core Graphic框架的代码
m_mainDisplay = kCGDirectMainDisplay;
m_oriImage = CGDisplayCreateImage(m_mainDisplay);
if (m_oriImage == NULL)
{
throw Exception ("Core Graphic Can not Create original Image from display",VF_ERR_SCREEN_MONITOR_OSX_CG_CREATE);
}
ScreenGetConfigure(m_oriImage);
screenData.m_oriImage = m_oriImage;
m_oriPixelDataRef = CGDataProviderCopyData(CGImageGetDataProvider(m_oriImage));
if (m_oriPixelDataRef == NULL)
{
throw Exception ("Core Graphic Can not get pixel data ref",VF_ERR_SCREEN_MONITOR_OSX_CG_CREATE);
}
两个代码都没有在登录前会话中工作。 希望有人可以帮我解决问题
MacBook,OS X El Capitan(10.11)