从CIImage获取CGImage [英] Getting a CGImage from CIImage

查看:1267
本文介绍了从CIImage获取CGImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从CIImage加载的UIImage:

I have a UIImage which is loaded from a CIImage with:

tempImage = [UIImage imageWithCIImage:ciImage];

问题是我需要将 tempImage 裁剪为特定的 CGRect ,我知道如何做到这一点的唯一方法是使用 CGImage
问题是在iOS 6.0文档中我发现了这个:

The problem is I need to crop tempImage to a specific CGRect and the only way I know how to do this is by using CGImage. The problem is that in the iOS 6.0 documentation I found this:

CGImage

如果使用CIImage对象初始化UIImage对象,则该属性的值为NULL。

A。如何转换CIImage至CGImage?
我正在使用此代码,但我有内存泄漏(并且无法理解在哪里):

A. How to convert from CIImage to CGImage? I'm using this code but I have a memory leak (and can't understand where):

+(UIImage*)UIImageFromCIImage:(CIImage*)ciImage {  
    CGSize size = ciImage.extent.size;  
    UIGraphicsBeginImageContext(size);  
    CGRect rect;  
    rect.origin = CGPointZero;  
    rect.size   = size;  
    UIImage *remImage = [UIImage imageWithCIImage:ciImage];  
    [remImage drawInRect:rect];  
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    remImage = nil;  
    ciImage = nil;  
    //
    return result;  
}


推荐答案

查看 CIContext createCGImage:fromRect:

CGImageRef img = [myContext createCGImage:ciImage fromRect:[ciImage extent]];

从回答类似问题: https://stackoverflow.com/a/10472842/474896

此外,因为你有 CIImage 首先,您可以使用 CIFilter 来实际裁剪图像。

Also since you have a CIImage to begin with, you could use CIFilter to actually crop your image.

这篇关于从CIImage获取CGImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆