2日前に正常に実行されていたコードでエラーが発生しました。エラーは次のとおりです。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType extent]: unrecognized selector sent to instance 0x1bc8f0'
main.mのこの行を指しています。
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
ログを使用してコードがどこに到達するかを確認すると、次の行がエラーをスローしているようです。
greySave = [context createCGImage:greyscaleImage fromRect:[greyscaleImage extent]];
greySaveはCGImageRefであり、ビューコントローラの起動時に宣言されます。CIImage出力を取得し、それをCGImageRefに変換して保存するのは簡単です。
desaturate = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:kCIInputImageKey, colourSave, @"inputIntensity", [NSNumber numberWithFloat:0.00], nil];
greyscaleImage = [desaturate valueForKey:@"outputImage"];
greySave = [context createCGImage:greyscaleImage fromRect:[greyscaleImage extent]];
私が変更した唯一のことは(理由はわかりませんが)問題を引き起こしている可能性があると思うのは、追加の条件ステートメントを追加することです。これにより、ユーザーが希望する2番目のフィルターが適用されます。
if ([_alphaButtonSavedState isEqualToString:@"ON"]) {
NSLog(@"user does want alpha on greyscale");
//user wants alpha mask also
} else {
NSLog(@"user does not want alpha on greyscale");
//convert to CGImage for saving
greySave = [context createCGImage:greyscaleImage fromRect:[greyscaleImage extent]];
NSLog(@"greySave cgimage created");
//save the grey image
[library writeImageToSavedPhotosAlbum:greySave metadata:[greyscaleImage properties] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"ERROR in greyscale save: %@", error);
} else
{
NSLog(@"SUCCESS in greyscale save");
//in here we'll put a nice animation or something
//CGImageRelease(greyscaleImage);
}
}];
なぜこれが起こっているのか考えはありますか?
ありがとう。
編集:
これが役立つ場合に備えて、コードのチャンク全体を示します。
[stillImage captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; //get the raw image data from the session
UIImage *startImage = [[UIImage alloc] initWithData:imageData]; //create a UIImage from that image data, let's us work with it
//resizing of image to take place before anything else
UIImage *image = [UIImage imageWithImage:startImage scaledToSize:_exportSSize]; //scale the image so it's shortest side is the size given in prefs
NSLog(@"image width post scale: %g", image.size.width);
NSLog(@"image height post scale is: %g", image.size.height);
//change the context to render using cpu, so on app exit renders get completed
context = [CIContext contextWithOptions: [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:kCIContextUseSoftwareRenderer]];
//new crop testing - not using CIImage - seems to work, just need to sort out crop region
CGRect cropRect = CGRectMake(0, 0, _exportSize, _exportSize);
UIImage *cropper = [self imageByCropping:image toRect:cropRect];
//the colour image is always saved so create a CGImage to save later
colourSave = [cropper CGImage];
NSLog(@"coloursave image created");
//now we convert and create CGImages based upon chosen export options
if ([_greyButtonSavedState isEqualToString:@"ON"]) {
NSLog(@"inside the greyscale conditional");
//user wants greyscale image
//create a CIMonochrome filter
desaturate = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:kCIInputImageKey, colourSave, @"inputIntensity", [NSNumber numberWithFloat:0.00], nil];
NSLog(@"desat ci filter created");
//get the output
greyscaleImage = [desaturate valueForKey:@"outputImage"];
NSLog(@"dest output image created");
//if the user wants to add the alpha
if ([_alphaButtonSavedState isEqualToString:@"ON"]) {
NSLog(@"user does want alpha on greyscale");
//user wants alpha mask also
} else {
NSLog(@"user does not want alpha on greyscale");
//convert to CGImage for saving
greySave = [context createCGImage:greyscaleImage fromRect:[greyscaleImage extent]];
NSLog(@"greySave cgimage created");
//save the grey image
[library writeImageToSavedPhotosAlbum:greySave metadata:[greyscaleImage properties] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"ERROR in greyscale save: %@", error);
} else
{
NSLog(@"SUCCESS in greyscale save");
//in here we'll put a nice animation or something
}
}];
}
}
-ここにさらに2つの条件があり、どちらも現在空です
--続いてcolourSaveイメージの保存を行います。これは正常に機能します。
-その後、メソッドは終了します。
もう1つ、これが画像のトリミング方法です。次のメソッドから返される画像は、CIImageの作成元です。
-(UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage]、rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}