来自相机的原始图像数据 [英] Raw image data from camera
问题描述
我一直在这个论坛上下搜索,但我找不到我真正需要的。我想从相机获得原始图像数据。到目前为止,我试图从该方法 captureStillImageAsynchronouslyFromConnection:completionHandler:
获取数据,并写入到 NSData $ c>中的imageDataSampleBuffer $ c> object,但是没有工作。
也许我在错误的轨道,也许我只是做错了。
我不想要的是以任何方式压缩图像。
简单的方法是使用 jpegStillImageNSDataRepresentation:从
AVCaptureStillImageOutput
这是我怎么做的:
1:我首先打开相机:
$ b b
- (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,@);
}
}
当拍摄照片时, / p>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Save and获取图像的路径
NSString * mediaType = [info objectForKey:UIImagePickerControllerMediaType];
ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];
if([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
//保存图片
image = [info objectForKey:@UIImagePickerControllerOriginalImage];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL * assetURL,NSError * error){
if(!error){
//保存数据库的路径和位置
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 {
//错误
}
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError * error)
{
NSString * errorString = [NSString stringWithFormat:@无法获取图像,%@,[错误localizedDescription] ];
NSLog(@%@,errorString);
};
if(filePathPicture&& [filePathPicture length])
{
NSURL * assetUrl = [NSURL URLWithString:filePathPicture];
ALAssetsLibrary * assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:assetUrl
resultBlock:resultBlock
failureBlock:failureBlock];
}
}
希望这有助于你更进一步:-)。
I've been searching this forum up and down but I couldn't find what I really need. I want to get raw image data from the camera. Up till now I tried to get the data out of the imageDataSampleBuffer from that method captureStillImageAsynchronouslyFromConnection:completionHandler:
and to write it to an NSData
object, but that didn't work.
Maybe I'm on the wrong track or maybe I'm just doing it wrong.
What I don't want is for the image to be compressed in any way.
The easy way is to use jpegStillImageNSDataRepresentation:
from AVCaptureStillImageOutput
, but like I said I don't want it to be compressed.
Thanks!
This is how i do it:
1: I first open the camera using:
- (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", @"");
}
}
When the picture is taken this method gets called:
-(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];
}
Then with that path i get the picture from the library in FULL resolution (using the "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];
}
}
Hope this helps you a bit further :-).
这篇关于来自相机的原始图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!