2012-05-04 2 views
0

내가 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"]; 

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"); 
    } 

    }]; 

그러나,이 예외 :

나는 그때 그것을 저장할 수 있도록의 CGImage이 다시 변환하려고 해요 오류가 :

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 픽셀이라면이 발생할 수 있음을, 그리고의 CGImage에 CIImage에서 변환이 문제를 일으킬 수있는 다른 곳에서 읽었습니다. 어떤 아이디어?

감사합니다.

+0

나는 이것을 저장하려고 시도하는 이미지에 치수가 없기 때문에 너비와 높이가 null로 보입니다. "2012-05-06 14 : 39 : 22.886 zApp [5108 : 707] 저장되는 이미지의 너비가 다음과 같습니다. (null) 2012-05-06 14 : 39 : 22.890 zApp [5108 : 707] 저장되는 이미지의 높이가 : (null) " – mrEmpty

+0

NSLog 코드에서 오류가 발생했습니다. 저장하려고하는 이미지가 0x0 픽셀인지 확인할 수 있습니다. 그래서 나는 문제라고 생각하지만, 그것이 어떻게 될지 알 수 없다. – mrEmpty

답변

1

나는 그것을 얻었습니다 (배틀 필드 3에서 20 분이 나에게 생각할 시간을주었습니다 - 어떤 PS3 BF3 플레이어가 나에게 메시지를 보내고 싶다는 것을 상기시켜줍니다).

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; 
UIImage *image = [[UIImage alloc] initWithData:imageData]; 
NSLog(@"*image size is: %@", NSStringFromCGSize(image.size)); 

//test creating a new ciimage 
CIImage *ciImage = [[CIImage alloc] initWithCGImage:[image CGImage]]; 
NSLog(@"ciImage extent: %@", NSStringFromCGRect([ciImage extent])); 

이 나에게 가능한 CIImage을 제공 : 내가 무슨 짓을

는 모든 내 태피 코드를 교체합니다. 나는 그걸로 저장하기 전에, 그걸로 필터 재미있을 수 있습니다 :

많은 쓰레기 라인을 무시하십시오, 내 테스트했다. 그들은 이제 없앨 수 있습니다.

나는 정원을 다녀 오는 축하연이 다가와서 기쁩니다.

+0

cropColourImage가 오류로 해제되지 않은 이유는 무엇입니까? –

관련 문제