I'm creating button dynamically in iPhone but I want to set the background from the gallery in iPhone. Now I want to know how to get the image form the gallery in iPhone.
问问题
287 次
3 回答
3
-(IBAction)btnSelectPhotoClick:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Photo Library Does Not Exist"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
// set it in image view
imageview.image = image;
// If it's from camera, save it!
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera){
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
[picker dismissModalViewControllerAnimated:YES];
}
// Catch when it's canceled
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
希望这对您有帮助,如果您有任何疑问,请告诉我。谢谢
于 2013-01-24T13:10:44.170 回答
1
如果您给用户选择图像的机会,那么 UIImagePickerController 将很有用。有关更多信息,请使用此 URL http://blog.hanpo.tw/2012/01/uiimagepickercontroller-and-simple.html
于 2013-01-24T13:04:41.030 回答
1
您可以像这样从图库中获取图像
- (void)choosePhotos{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
YourImageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
于 2013-01-24T13:05:33.653 回答