UIImagePickerControlle
来源:互联网 发布:淘宝联盟等级划分 编辑:程序博客网 时间:2024/04/29 15:02
一:UI 显示样式,显示的格式确定
1:sourceType
@property(nonatomic) UIImagePickerControllerS
enum {
UIImagePickerControllerS
UIImagePickerControllerS
UIImagePickerControllerS
};
typedef NSUInteger UIImagePickerControllerS
sourceType用来确定用户界面显示的样式:
共三种格式(模拟器上的效果图)
UIImagePickerControllerS
UIImagePickerControllerS
UIImagePickerControllerS
为了区分是否支持所需引用的sourceType,一般要用到下面这个函数,以便确定sourceType。
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerS
2:
@property(nonatomic,copy) NSArray *mediaTypes
mediaTypes用来确定再picker里显示那些类型的多媒体文件,图片?视频?
+ (NSArray *)availableMediaTypesForSo
UIImagePikerController的一些属性和方法:
@property(nonatomic)
@property(nonatomic,copy)
@property(nonatomic)
@property(nonatomic)
//视频最大的时间长度
@property(nonatomic)
//拍摄照片的清晰度,只有在照相机模式下可用
enum {
};
typedef NSUInteger UIImagePickerControllerQ
默认UIImagePickerControllerQ
@property(nonatomic)
//是否显示照相机其他控件,默认yes
@property(nonatomic)
//类似相框
@property(nonatomic,retain)
@property(nonatomic)
//可以设置照相机的模式,照相还是录视频,默认照相模式。
enum {
};
typedef NSUInteger UIImagePickerControllerC
@property(nonatomic) UIImagePickerControllerC
//设置哪个引用摄像头,前置还是后置摄像头
@property(nonatomic) UIImagePickerControllerC
//设置闪光灯模式
enum {
};
typedef NSInteger UIImagePickerControllerC
@property(nonatomic) UIImagePickerControllerC
二:选取动作处理
UIImagePickerControllerD
通过代理来完成用户在选中图片,或者choose视频时的处理方式:
共有三个可选的代理方法
- (void)imagePickerController:(UIImagePickerController
- (void)imagePickerControllerDid
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo;
info中包括选取的照片,视频的主要信息
NSString *const UIImagePickerControllerM
NSString *const UIImagePickerControllerO
NSString *const UIImagePickerControllerE
NSString *const UIImagePickerControllerC
NSString *const UIImagePickerControllerM
保存视频主要时通过获取其NSURL 然后转换成NSData
保存图片、视频的方法。
// Adds a photo to the saved photos album.
//
UIKIT_EXTERN void UIImageWriteToSavedPhoto
// Is a specific video eligible to be saved to the saved photos album?
UIKIT_EXTERN BOOL UIVideoAtPathIsCompatibl
// Adds a video to the saved photos album. The optional completionSelector should have the form:
//
UIKIT_EXTERN void UISaveVideoAtPathToSaved
实例代码如下:
实例一:
- (void) pickImage: (id) sender
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.allowsImageEditing = NO;
[self presentModalViewControll
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWit
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerM
if ([mediaType isEqualToString:@"public.image"]){
// UIImage *selectedImage = [info objectForKey:UIImagePickerControllerO
UIImage *image = [info objectForKey:@"UIImagePickerControllerO
[UIImageJPEGRepresentatio
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerM
NSLog(@"found a video");
//NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];
[webData writeToFile:[self findUniqueMoviePath] atomically:YES];
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
// NSLog(videoURL);
}
[picker dismissModalViewControll
}
实例二:主要介绍怎么修改获取图片的方法
加一个图片处理方法的类:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
CGFloat scale = 100/selectedImage.size.height;
UIImage *newpetimage = [selectedImage scaleToSize:CGSizeMake(selectedImage.size.width*scale, selectedImage.size.height*scale)];
NSLog(@"imagew = %f,h = %f",newpetimage.size.width,newpetimage.size.height);
}
- UIImagePickerControlle
- iOS摄像头和相册-UIImagePickerControlle
- 通过调用系统摄像头拍照,拍视频
- Hacking Custom Authentication Providers with Grails Spring Security
- Magento网店自定义模板初探(3)——缓存设置
- CListCtrl使用技巧
- Memcached - PHP 安装&使用
- UIImagePickerControlle
- 结构体对齐和类的大小
- const修饰符浅析
- 学习实用英语(3)
- IOCP浅析(一)
- 什么是线程安全和线程不安全
- 衷心的感谢同行们的支持与鼓励,我才会有这个机会!
- C/S通讯,关于java.net.SocketTimeoutException:Read time out:错误
- 免费的工具-Fiddler(查探Vault API的调用流程)