SIGABRT 投射到 UIImage
SIGABRT on cast to 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 的引用感到困惑。我的类型转换有问题吗?没有关于构建的投诉。有人可以让我直截了当吗?
阅读 FastttCapturedImage
的文档。它不是 UIImage
所以你不能像那样投射它。使用提供的 属性 获取 UIImage
.
将有问题的行更改为:
NSData *pngData = UIImagePNGRepresentation(capturedImage.fullImage);
您稍后遇到同样的问题:
[self.viewFinder setImage:capturedImage.fullImage];
顺便说一句 - 你在编译时没有遇到问题,因为转换是一种告诉编译器的方式 "trust me, it's really what I'm telling you it is"。这里的问题是你错了,这不是你声称的那样。 :)
我正在使用 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 的引用感到困惑。我的类型转换有问题吗?没有关于构建的投诉。有人可以让我直截了当吗?
阅读 FastttCapturedImage
的文档。它不是 UIImage
所以你不能像那样投射它。使用提供的 属性 获取 UIImage
.
将有问题的行更改为:
NSData *pngData = UIImagePNGRepresentation(capturedImage.fullImage);
您稍后遇到同样的问题:
[self.viewFinder setImage:capturedImage.fullImage];
顺便说一句 - 你在编译时没有遇到问题,因为转换是一种告诉编译器的方式 "trust me, it's really what I'm telling you it is"。这里的问题是你错了,这不是你声称的那样。 :)