gpt4 book ai didi

ios - SIGABRT 转换为 UIImage

转载 作者:行者123 更新时间:2023-11-29 02:03:03 26 4
gpt4 key购买 nike

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

- (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];

顺便说一句 - 你在编译时没有遇到问题,因为强制转换是一种告诉编译器“相信我,这真的是我告诉你的”的方式。这里的问题是你错了,这不是你声称的那样。 :)

关于ios - SIGABRT 转换为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com