从相机的RAW图像数据(Raw image data from camera)

2019-09-17 10:25发布

我一直在寻找这个论坛上下,但我无法找到我真正需要的。 我想从摄像机获得原始图像数据。 到现在为止我试图让数据从imageDataSampleBuffer从该法的captureStillImageAsynchronouslyFromConnection:completionHandler:并将其写入一个NSData对象,但没有奏效。 也许我是在错误的轨道上或也许我只是做是错误的。 我不希望是图像以任何方式进行压缩。

最简单的方法是使用jpegStillImageNSDataRepresentation:AVCaptureStillImageOutput ,但就像我说的,我不希望它被压缩。

谢谢!

Answer 1:

这就是我要做的事:

1:我第一次使用打开相机:

- (void)openCamera
{
    imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {        
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              (NSString *) kUTTypeMovie, nil];
        imagePicker.allowsEditing = NO;

        [self presentModalViewController:imagePicker animated:YES];
    }
    else {
        lblError.text = NSLocalizedStringFromTable(@"noCameraFound", @"Errors", @"");  
    }
}

当拍摄照片后调用此方法:

 -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // Save and get the path of the image
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
    {
        // Save the image
        image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
            if(!error) {
               //Save path and location to database
               NSString *pathLocation = [[NSString alloc] initWithFormat:@"%@", assetURL];
            } else {
                NSLog(@"CameraViewController: Error on saving image : %@ {imagePickerController}", error);
            }
        }];

    }
    [imagePicker dismissModalViewControllerAnimated:YES];
}

然后用这条道路我得到全分辨率库中的图片(使用“1”):

 -(void)preparePicture: (NSString *) filePathPicture{
    ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myasset)
    {
        if(myasset != nil){
            ALAssetRepresentation *assetRep = [myasset defaultRepresentation];
            CGImageRef imageRef = [assetRep fullResolutionImage];
            if (imageRef) {
                NSData *imageData = UIImageJPEGRepresentation([UIImage imageWithCGImage:imageRef], 1);
            }
        }else {
            //error
        }
     };

    ALAssetsLibraryAccessFailureBlock failureBlock  = ^(NSError *error)
    {      
         NSString *errorString = [NSString stringWithFormat:@"can't get image, %@",[error localizedDescription]];
        NSLog(@"%@", errorString);
    };

     if(filePathPicture && [filePathPicture length])
     {
         NSURL *assetUrl = [NSURL URLWithString:filePathPicture];
         ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
        [assetslibrary assetForURL:assetUrl 
                   resultBlock:resultBlock
                  failureBlock:failureBlock];
    }
}

希望这有助于你远一点:-)。



文章来源: Raw image data from camera