解決する必要がある機能: バックグラウンド デスクトップ ビデオ録画 NSTimer サイクル スクリーンショット用の IOSurface 呼び出しを使用します,次のコード:</p>
NSTimer * Timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(ScreenShot) userInfo:nil repeats:YES];
-(void)ScreenShot{io_service_t framebufferService;
framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleH1CLCD"));
if (!framebufferService) {
framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleM2CLCD"));
}
if (!framebufferService) {
framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleCLCD"));
}
IOMobileFramebufferConnection connect;
kern_return_t result;
IOSurfaceRef ScreenSurface;
result = IOMobileFramebufferOpen(framebufferService, mach_task_self(), 0, &connect);
result = IOMobileFramebufferGetLayerDefaultSurface(connect, 0, &ScreenSurface);uint32_t aseed;
uint32_t Width;
uint32_t Height;
int Pitch;
int size;
int bPE;
CFMutableDictionaryRef dict;
IOSurfaceLock(ScreenSurface, kIOSurfaceLockReadOnly, &aseed);
Width = IOSurfaceGetWidth(ScreenSurface);
Height = IOSurfaceGetHeight(ScreenSurface);
Pitch = Width * 4;
size = Width * Height * 4;
bPE = 4;
char pixelFormat[4] = {'A','R','G','B'};
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(dict, kIOSurfaceIsGlobal, kCFBooleanTrue);
CFDictionarySetValue(dict, kIOSurfaceBytesPerRow, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &Pitch));
CFDictionarySetValue(dict, kIOSurfaceBytesPerElement, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bPE));
CFDictionarySetValue(dict, kIOSurfaceWidth, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &Width));
CFDictionarySetValue(dict, kIOSurfaceHeight, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &Height));
CFDictionarySetValue(dict, kIOSurfacePixelFormat, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, pixelFormat));
CFDictionarySetValue(dict, kIOSurfaceAllocSize, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &size));
CGDataProviderRef provider;
IOSurfaceRef destSurf;
void* outAcc;
CGImageRef cgImage;
destSurf = IOSurfaceCreate(dict);
IOSurfaceAcceleratorCreate(NULL, 0, &outAcc);
IOSurfaceAcceleratorTransferSurface(outAcc, ScreenSurface, destSurf, dict, NULL);
IOSurfaceUnlock(ScreenSurface, kIOSurfaceLockReadOnly, &aseed);
CFRelease(outAcc);
provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(destSurf), (Width * Height * 4), NULL);
cgImage = CGImageCreate(Width, Height, 8, 8*4, IOSurfaceGetBytesPerRow(destSurf), CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, provider, NULL, YES, kCGRenderingIntentDefault);}
成功をスクリーンショットできます。</p>
問題は次のとおりです。
- ただし、おそらく 1 分ほど実行すると、「メモリ警告を受信しました」というプロンプトが表示されます。</li>
- スライドスクリーン、スクリーン方式が遅くなる
または、どのような方法でデスクトップ ビデオをバックグラウンドで録画できますか?</p>