gpt4 book ai didi

ios - 释放 IOSurface

转载 作者:可可西里 更新时间:2023-11-01 03:33:12 39 4
gpt4 key购买 nike

这个问题是对:
的扩展链接-1:Creating an image out of the ios surface and saving it
Link-2:Taking Screenshots from iOS app - emulating Display recorder (query on the internals)

(引用 Link-1)我有在后台运行的截屏代码。但如前所述,它需要 2 秒的 sleep 才能不间断地工作,否则操作系统会暂停应用程序。我发现原因可能是我没有明确发布我创建的 IOSurface。
原因 - 使用链接 http://pastie.org/pastes/3734430由 Victor Ronin 给出,即使没有 sleep ,捕获也能正常工作。我尝试在每次写入图像后使用 CFRelease 释放 destSurf(我创建的目标表面),但这不起作用。

任何关于何时、如何以及是否发布创建的 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);
  1. 对 CFRelease 的调用发生并且应用程序崩溃。没有保存图像。但是,如果您在释放前先休眠 1-2 秒,效果会很好。
  2. 如果您跳过对 UIImageWriteToSavePhotosAlbum() 的调用,一切都会正常进行并且捕获不会中断。
    我仍然不清楚问题到底是什么以及如何解决。非常感谢任何帮助。

最佳答案

关于ios - 释放 IOSurface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952313/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com