[英]Save taken image in photo library
I have coded this program to save image while picking the uiimage but i need to code to save the image in UIImagePickerControllerSourceTypePhotoLibrary while capturing the 我已经对该程序进行了编码,以在拾取uiimage时保存图像,但是我需要编码以在捕获UIimagePickerControllerSourceSourcePhotoPhotoLibrary时保存图像
image by camera only. 仅由相机拍摄。
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if([info objectForKey:@"UIImagePickerControllerOriginalImage"])
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
PhotoViewController *photoVC=[[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
photoVC.photoImage=image;
photoVC.photoDelegate=self;
[self.navigationController pushViewController:photoVC animated:YES];
}
}
I think this will help you. 我认为这会对您有所帮助。 please try this one. 请试试这个。
This is code for taking a image using camera : 这是使用相机拍摄图像的代码:
UIImagePickerController *myImagePickerController = [[UIImagePickerController alloc]init];
myImagePickerController.delegate = self;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if (YES == [UIImagePickerController isSourceTypeAvailable:sourceType])
{
myImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:myImagePickerController.view];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning !!" message:@"Camera is not available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
This code for saving image on Photo Library : 此代码用于在照片库中保存图像:
UIImage *img = [UIImage imageNamed:@"image.png"]; // This is your after taking photo
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error != NULL)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:[[error localizedDescription] capitalizedString] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sucesses !!" message:@"Your image has been saved sucessefully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert setTag:100];
[alert release];
}
}
If you want to save picked image to photo library then use/write UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
如果要将选择的图像保存到照片库中,请使用/编写UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
function in didFinishPickingImage
didFinishPickingImage
函数
such like, 像这样
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[picker dismissModalViewControllerAnimated:NO];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ if([info objectForKey:@"UIImagePickerControllerOriginalImage"])
{
UIImage *tmpimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
if ((picker.sourceType=UIImagePickerControllerSourceTypeCamera)) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
PhotoViewController *photoVC=[[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
photoVC.photoImage=tmpimage;
photoVC.photoDelegate=self;
[self.navigationController pushViewController:photoVC animated:YES];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.