【问题标题】:kCGImagePropertyOrientation incompatible pointerkCGImagePropertyOrientation 指针不兼容
【发布时间】:2014-04-22 19:40:15
【问题描述】:

我正在我的应用中实现自动增强功能。我的代码是这样的:

CIImage *toBeEnhancedImage = [CIImage imageWithCGImage:_originalImage.CGImage];

NSDictionary *options = @{CIDetectorImageOrientation : [[toBeEnhancedImage properties] valueForKey:kCGImagePropertyOrientation]};

NSArray *adjustments = [toBeEnhancedImage autoAdjustmentFiltersWithOptions:options];

在运行代码之前,我在 NSDictionary 旁边收到以下错误:

不兼容的指针类型将 'const CFStringRef (AKA 'const struct__CFString const) 发送到 NSString* 类型的参数

当我运行代码时,它崩溃了。我知道错误的含义,但代码实际上是从 Apple 的文档中获取的,它不起作用!有解决办法吗?

【问题讨论】:

    标签: ios core-image


    【解决方案1】:

    您应该键入将您的CFStringRef 变量转换为NSString *。用以下几行更改代码的第二行:

    NSDictionary *options = nil;
    if([[toBeEnhancedImage properties] valueForKey:(NSString *)kCGImagePropertyOrientation] == nil)
    {
        options = @{CIDetectorImageOrientation : [NSNumber numberWithInt:1]};
    }
    else
    {
       options = @{CIDetectorImageOrientation : [[toBeEnhancedImage properties] valueForKey:(NSString *)kCGImagePropertyOrientation]};
    }
    

    【讨论】:

    • 进行了更改,但应用程序仍然在同一行崩溃,尽管它没有显示黄色警报。
    • 什么是控制台日志?我认为您正在尝试在字典中插入 nil 值。
    • 好的,这里显示的是:*** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: 尝试插入 nil 对象from objects[0]' *** First throw call stack: (0x2d953f4b 0x380c26af 0x2d89217b 0x2d891f43 0xe046b 0x300cb37b 0x300cb139 0x302573eb 0x30175273 0x3017507d 0x30175015 0x300c6da3 0x2fd4dc6b 0x2fd4947b 0x2fd4930d 0x2fd48d1f 0x2fd48b2f 0x2d91ceb3 0x2d887c27 0x2d887a0b 0x3257b283 0x3012b049 0x10e98d 0x385caab7) libc++abi.dylib: terminating with uncaught NSException 类型的异常
    • 没有。您的图像没有方向属性。所以你试图在字典中插入 NULL 。该属性的默认值为 NSNumber,值为 1。因此,我们相应地对其进行更改。
    • 谢谢,像丝绸一样工作!令人惊讶的是,Apple 发布的代码如此糟糕。我确信,100%,他们讨厌与开发人员打交道。写一个像样的文档是我们永远不会看到的。
    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多