UIAction的使用和调用系统相册和相机
2014-09-06 10:32
435 查看
实现UIActionSheetDelegate
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: @""
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"图库相册",@"拍照", nil];
[menu showInView:self.view];
# pragma mark UIActionSheet method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) {
[self photoalbumr];//图库相册
}else if(buttonIndex==1){
[self photocamera];//拍照
}else if(buttonIndex==2){
}
[actionSheet release];
}
调用系统的相簿
实现UIImagePickerControllerDelegate
-(void)photoalbumr{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Drat!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void)photocamera{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* imagepicker = [[UIImagePickerController alloc] init];
imagepicker.delegate = self;
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagepicker.allowsEditing = YES;
[self presentModalViewController:imagepicker animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"设备不支持拍照功能"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark UIImagePicker method
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
/*将图片存储到document下
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
_imgName=@"savedImage.png";
self._imgFilePath=documentsDirectory;
*/
[addPhoto setBackgroundImage:image forState:UIControlStateNormal];
[picker dismissModalViewControllerAnimated:YES];
}
// 完成选取
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: @""
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"图库相册",@"拍照", nil];
[menu showInView:self.view];
# pragma mark UIActionSheet method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) {
[self photoalbumr];//图库相册
}else if(buttonIndex==1){
[self photocamera];//拍照
}else if(buttonIndex==2){
}
[actionSheet release];
}
调用系统的相簿
实现UIImagePickerControllerDelegate
-(void)photoalbumr{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Drat!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void)photocamera{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* imagepicker = [[UIImagePickerController alloc] init];
imagepicker.delegate = self;
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagepicker.allowsEditing = YES;
[self presentModalViewController:imagepicker animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"设备不支持拍照功能"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark UIImagePicker method
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
/*将图片存储到document下
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
_imgName=@"savedImage.png";
self._imgFilePath=documentsDirectory;
*/
[addPhoto setBackgroundImage:image forState:UIControlStateNormal];
[picker dismissModalViewControllerAnimated:YES];
}
// 完成选取
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
相关文章推荐
- UIActionSheet的使用和系统相机的相关调用
- iOS使用UIImagePickerController调用系统相机、相册与图库
- h5 app开发使用cordova调用相册、相机、文件系统或录音录视频,并上传到服务器
- Android调用系统相机相册,可选择性裁剪
- 【Android】使用系统相机或者从相册中获取图片资源并进行适当裁剪
- IOS开发笔记之十四——使用系统相册或相机导致状态栏隐藏的问题(bug总结四)
- ios开发调用系统相机相册
- 调用相机拍照并得到图片-------得到系统相册中一张图片
- Android 调用系统相机拍照保存以及调用系统相册的方法
- Android 调用系统相机拍照保存以及调用系统相册的方法
- android调用系统相机与系统相册
- iOS开发中使用相机或系统相册的一些问题总结(UIImagePickerController)
- 系统相册的调用,和相机的调用
- iOS调用系统相册、相机 显示中文标题
- android中调用系统相机拍照并访问本地相册
- iOS-UIActionSheet的简单使用和调用系统相簿
- iOS图片处理(一)————调用系统相机和相册获取图片,给相机添加自定义覆盖物
- 如何在调用系统相册相机时,将显示的英文(photos)改为中文
- 调用系统相册和系统相机拍照
- Android开发之系统相机相册使用