iOS9开发技术Swift2.0 开发技术tom

iOS截屏遇到的bug

2016-08-10  本文已影响346人  肖浩呗
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];   //截图
    UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

在本代码中,有两个需要注意的有可能关系到内存的问题

因为UIGraphicsGetImageFromCurrentImageContext()返回的是一个autoreleaseUIImage对象

因为UIGraphicsBeginImageContextWithOptions()会在函数体内部通过
CGBitmapContetAlloc内部函数分配内存空间,而UIGraphicsEndImageContext ()的作用就是释放该空间。

上一篇 下一篇

猜你喜欢

热点阅读