我有一个形象,我是从AVFoundation抓:保存CIImage,通过转换为CGImage,抛出一个错误
[stillImage captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
NSLog(@"image capture");
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
我那么首先转换为CIImage剪裁此图片:
beginImage = [CIImage imageWithCVPixelBuffer:CMSampleBufferGetImageBuffer(imageSampleBuffer) options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNull null], kCIImageColorSpace, nil]];
//first we crop to a square
crop = [CIFilter filterWithName:@"CICrop"];
[crop setValue:[CIVector vectorWithX:0 Y:0 Z:70 W:70] forKey:@"inputRectangle"];
[crop setValue:beginImage forKey:@"inputImage"];
croppedColourImage = [crop valueForKey:@"outputImage"];
我再尝试转换这回CGImage,这样我可以节省出来:
CGImageRef cropColourImage = [context createCGImage:croppedColourImage fromRect:[croppedColourImage extent]];
UIImage *cropSaveImage = [UIImage imageWithCGImage:cropColourImage];
//saving of the images
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[cropSaveImage CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"ERROR in image save :%@", error);
} else
{
NSLog(@"SUCCESS in image save");
}
}];
但是,这将引发错误:
ERROR in image save :Error Domain=ALAssetsLibraryErrorDomain Code=-3304 "Failed to encode image for saved photos." UserInfo=0x19fbd0 {NSUnderlyingError=0x18efa0 "Failed to encode image for saved photos.", NSLocalizedDescription=Failed to encode image for saved photos.}
我读过其他地方,这可能发生,如果图像是为0x0像素,以及从CIImage到CGImage转换可能会导致问题。有任何想法吗?
谢谢。
我相信这是因为我试图保存的图像没有尺寸,宽度和高度显示为空。 “2012-05-06 14:39:22.886 zApp [5108:707]正在保存的图像的宽度为:(null) 2012-05-06 14:39:22.890 zApp [5108:707]正在保存的图像的高度为:(null)“ – mrEmpty
我在我的NSLog代码中有一个错误,我可以确认我想要保存的图像是0x0像素。所以我认为是问题所在,但我不明白会发生什么。 – mrEmpty