ios 图库的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
UIImagePickerControllerDelegate ,UINavigationControllerDelegate
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int){
PickerController = UIImagePickerController()
if buttonIndex == 0{//图库
PickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
}else if buttonIndex == 2{//相机 取消为1
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) == false{
return
}
PickerController.sourceType = UIImagePickerControllerSourceType.Camera
}
if buttonIndex==0||buttonIndex == 2{
PickerController.delegate = self
PickerController.allowsEditing = true
//PickerController.mediaTypes = [kUTTypeMovie!]//需要头文件支持 视频文件
//PickerController.videoQuality = UIImagePickerControllerQualityType.Type640x480
self.presentViewController(PickerController, animated: true) { () -> Void in
//println("页面跳转成功回调")
}
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]){
//println("选择")
// println("视频文件地址\(info[UIImagePickerControllerMediaURL])")
println("图片文件\(info[UIImagePickerControllerOriginalImage])")
//编辑后的image
let image = info[UIImagePickerControllerEditedImage] as! UIImage
// info[UIImagePickerControllerReferenceURL] 等等信息
//var url = info[UIImagePickerControllerMediaURL] as! NSURL
// println("url = \(url.URLString)")
// var avAsset = AVURLAsset(URL: url, options: nil)
// println("时间\(avAsset.duration.value) : \(avAsset.duration.timescale)")
var image = info[UIImagePickerControllerOriginalImage] as! UIImage
//self.presentViewController(upload, animated: true, completion: nil)
//self.navigationController?.pushViewController(upload, animated: true)
PickerController.dismissViewControllerAnimated(true, completion: { () -> Void in
})
}

// 保存到本地

1
2
3
4
5
6
7
8
9
10
11
12
UIVideoAtPathIsCompatibleWithSavedPhotosAlbum //拍摄的视频保存到相册
UISaveVideoAtPathToSavedPhotosAlbum(url.path, self, nil, nil)
UIImageWriteToSavedPhotosAlbum 拍摄的图片保存到本地
if picker.sourceType == UIImagePickerControllerSourceType.Camera{
let saveBool = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.path)
if saveBool == true{
UISaveVideoAtPathToSavedPhotosAlbum(url.path, self, nil, nil)
}
}

Author

陈昭

Posted on

2016-09-12

Updated on

2021-12-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Kommentare

You forgot to set the shortname for Disqus. Please set it in _config.yml.