这个问题是对以下问题的延伸:
链接-1:Creating an image out of the ios surface and saving it
链接-2:Taking Screenshots from iOS app - emulating Display recorder (query on the internals)
(参考链接-1)我有在后台工作的截图的代码。但是如前所述,它需要2秒的睡眠才能不间断地工作,否则操作系统就会挂起应用程序。我发现原因可能是我没有显式地发布我创建的IOSurface。
原因-使用维克多罗宁给出的链接http://pastie.org/pastes/3734430,捕捉工作良好,即使没有睡眠。每次写入图像后,我尝试使用destSurf (我创建的目标面)发布CFRelease,但这不起作用。
任何关于何时、如何以及是否发布创建的IOSurface的帮助都将是非常有用的。谢谢。
更新
所以,这就是到底发生了什么。(参考链接-1)
IOSurfaceRef destSurf = IOSurfaceCreate(dict);
IOSurfaceAcceleratorRef outAcc;
IOSurfaceAcceleratorCreate(NULL, 0, &outAcc);
CFDictionaryRef ed = (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: nil];
IOSurfaceAcceleratorTransferSurface(outAcc, screenSurface, destSurf, ed, NULL);
IOSurfaceUnlock(screenSurface, kIOSurfaceLockReadOnly, &aseed);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(destSurf), (width*height*4), NULL);
CGImageRef cgImage=CGImageCreate(width, height, 8, 8*4, IOSurfaceGetBytesPerRow(destSurf), CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, provider, NULL, YES, kCGRenderingIntentDefault);
UIImage *image = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
CFRelease(destSurf);发布于 2012-12-19 17:52:32
我认为你需要释放表面。它是由API IOSurfaceCreate创建的,它不是由自动发行版管理的。
例如,我发现下面的代码是发布的:
http://www.opensource.apple.com/source/WebCore/WebCore-7536.24/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp?txt
如果您试图用CFRelease发布它,会发生什么?它崩溃了还是有同样的2秒问题?
https://stackoverflow.com/questions/13952313
复制相似问题