SIGABRT投射到UIImage

时间:2015-05-08 04:49:42

标签: ios casting uiimage

我使用FastttCamera作为AVFoundation的包装器来拍摄,处理和显示图片。这是我的代码(FastttCamera委托方法),我将(FastttCapturedImage *)转换为(UIImage *):

- (void)cameraController:(FastttCamera *)cameraController didFinishScalingCapturedImage:(FastttCapturedImage *)capturedImage
{
    //Use the captured image's data--note that the FastttCapturedImage is cast to a UIImage
    NSData *pngData = UIImagePNGRepresentation((UIImage *)capturedImage);

    //Save the image, and add the path to this transaction's picPath attribute
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory

    int timestamp = [[NSDate date] timeIntervalSince1970];

    NSString *timeTag = [NSString stringWithFormat:@"%d",timestamp];

    NSString *filePath = [documentsPath stringByAppendingString:timeTag]; //Add the file name
    [pngData writeToFile:filePath atomically:YES]; //Write the file

    self.thisTransaction.picPath = filePath;

    [self.viewFinder setImage:(UIImage *)capturedImage];
}

然而,我在这一行得到了一个SIGABRT:

    NSData *pngData = UIImagePNGRepresentation((UIImage *)capturedImage);

使用此控制台读数:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FastttCapturedImage CGImage]: unrecognized selector sent to instance 0x17e2a100'

我对CGImage的引用感到困惑。这是我的类型转换的问题吗?没有关于构建的投诉。有人可以请我直截了当吗?

1 个答案:

答案 0 :(得分:1)

阅读FastttCapturedImage的文档。它不是UIImage所以你不能像那样投射它。使用提供的属性获取UIImage

将有问题的行更改为:

NSData *pngData = UIImagePNGRepresentation(capturedImage.fullImage);

您稍后遇到同样的问题:

[self.viewFinder setImage:capturedImage.fullImage];
BTW - 你在编译时没有遇到问题,因为演员阵容是告诉编译器“信任我,它真的是我告诉你的”。这里的问题是你错了,这不是你声称的那样。 :)