Swift中获取相册图片与保存到相册
关于这个网上目前位置记录的资料比较少,记录一下这个坑
获取相册图片
1: var iPC = UIImagePickerController()
2: iPC.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
3: iPC.delegate = self
4: presentViewController(iPC, animated: true) { () -> Void in
5: print("complete")
6: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
1: func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
2: // println(info)
3:
4: let img = info["UIImagePickerControllerOriginalImage"] as! UIImage
5: let pV = PhotoView(frame: paintView.frame, img: img)
6: view.addSubview(pV)
7: pV.delegate = self
8: photoView = pV
9: dismissViewControllerAnimated(true, completion: nil)
10: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
保存到系统相册
1: func save(){
2: UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
3: var ctx = UIGraphicsGetCurrentContext()
4: layer.renderInContext(ctx)
5: let img = UIGraphicsGetImageFromCurrentImageContext()
6: UIGraphicsEndImageContext()
7: UIImageWriteToSavedPhotosAlbum(img, self, "image:didFinishSavingWithError:contextInfo:", nil)
8: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
1: func image(image: UIImage, didFinishSavingWithError error:NSErrorNSError?, contextInfo:UnsafePointer<Void>){
2: // if let r = error {
3: // print(r)
4: // }else{
5: // let e:NSError? = error
6: if let ee = erroras NSError?{
7: print(ee)
8: }else{
9: UIAlertView(title:nil, message: "保存成功!", delegate: nil, cancelButtonTitle: "确定").show()
10: }
11: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
以上代码在2015/7更新优化
Ref:
http://stackoverflow.com/questions/24101468/checking-optionals-for-nil-in-swift
Swift中获取相册图片与保存到相册的更多相关文章
- 修正iOS从照相机和相册中获取的图片 方向
修正iOS从照相机和相册中获取的图片 方向 修正iOS从照相机和相册中获取的图片 方向 使用系统相机拍照得到的图片的默认方向有时不是ImageOrientationDown,而是ImageOrie ...
- iOSQuartz2D-04-手动剪裁图片并保存到相册
实现效果 操作步骤 绘制一个矩形框,弹出一个alertView,提示是否保存图片 点击"是",将图片保存到相册 在相册中查看保存的图片 效果图 实现思路 在控制器的view上添加一 ...
- Android中获取选择图片与获取拍照返回结果差异
导语: 如今的安卓应用在选择图片的处理上大多合并使用拍照和从相册中选择这两种方式 今天在写一个这样的功能时遇到一个尴尬的问题,同样是拍照获取图片功能,在不同手机上运行的效果不一样,下面是在某型手机上测 ...
- C# 从类库中获取资源图片,把图片资源保存到类库中
/// <summary> /// 获取资源图片 /// </summary> public class AssemblyHelper { #region 常量 /// < ...
- android把图片 视频 保存到相册
//android把图片文件添加到相册 ContentResolver localContentResolver = getContentResolver(); ContentValues local ...
- 修正iOS从照相机和相册中获取的图片方向(转)
- (UIImage *)fixOrientation { // No-op if the orientation is already correct if (self.imageOrientati ...
- 修正iOS从照相机和相册中获取的图片方向
使用系统相机拍照得到的图片的默认方向有时不是ImageOrientationDown,而是ImageOrientationLeft,在使用的时候会出现图片顺时针偏转90°.使用fixOrientati ...
- 系统相册中获取gif图片 保证取到的图片不会改变
NSURL *imageRefURL = [info valueForKey:UIImagePickerControllerReferenceURL]; ...
- SWIFT中获取配置文件路径的方法
在项目中有时候要添加一些配置文件然后在程序中读取相应的配置信息,以下为本人整理的获取项目配置文件(.plist)路径的方法: 1.获取沙盒路径后再APPEND配置文件 func documentsDi ...
随机推荐
- 获取html元素内容
html: <!DOCTYPE ><html> <head> <meta http-equiv="Content-Type" conten ...
- Rem与em的简单理解
Rem与em的简单理解 Em单位与像素px的转换 所得的像素值 = 当前元素的font-size * em的值 比如:div的font-size:12px 10em等同于120px 12*10 =12 ...
- L2-001. 紧急救援---(Dijkstra,记录路径)
https://www.patest.cn/contests/gplt/L2-001 L2-001. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 ...
- Python用户登陆
#!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinfo.txt ...
- Pycharm2017汉化包下载链接
https://github.com/ewen0930/PyCharm-Chinese/tree/f5a8dc4a8f34398e81a69c69bb046aa4eff27c90 1.首先下载PyCh ...
- UVALIVE 3486 Cells
通过入栈出栈顺序判断祖先关系 这里UVALIVE还 #include <map> #include <set> #include <list> #include & ...
- LINUX环境下的GUN MAKE学习笔记(二)
第三章:makefile总述 3.1makefile的内容 在一个完整的makefile中,包含显示规则.隐含规则.变量定义.指示符和注释.下面讨论一些基本概念: 显示规则:它描述了在何种情况下如何更 ...
- picker鼠标上下拖动选择内容
上次写这个的时候的博客:http://hiuman.iteye.com/blog/2324929 上次是网上搜的,这次是自己写的. 无论多少个input都可以点击-但是只有一种内容(弹出的内容),可以 ...
- HTML布局相关的CSS样式属性
# 转载请留言联系 注意,样式属性是写进CSS里面的. 布局常用样式属性: width 设置元素(标签)的宽度,如:width:100px; height 设置元素(标签)的高度,如:height:2 ...
- python中的三元表达式
if B = True: return A else: return C 用三元表达式可以写成: return A if B else C