关于这个网上目前位置记录的资料比较少,记录一下这个坑

获取相册图片

   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 = error as 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/25108888/strugglig-to-convert-objective-c-selector-and-target-signature-to-swift

http://stackoverflow.com/questions/24101468/checking-optionals-for-nil-in-swift

Swift中获取相册图片与保存到相册的更多相关文章

  1. 修正iOS从照相机和相册中获取的图片 方向

    修正iOS从照相机和相册中获取的图片 方向   修正iOS从照相机和相册中获取的图片 方向 使用系统相机拍照得到的图片的默认方向有时不是ImageOrientationDown,而是ImageOrie ...

  2. iOSQuartz2D-04-手动剪裁图片并保存到相册

    实现效果 操作步骤 绘制一个矩形框,弹出一个alertView,提示是否保存图片 点击"是",将图片保存到相册 在相册中查看保存的图片 效果图 实现思路 在控制器的view上添加一 ...

  3. Android中获取选择图片与获取拍照返回结果差异

    导语: 如今的安卓应用在选择图片的处理上大多合并使用拍照和从相册中选择这两种方式 今天在写一个这样的功能时遇到一个尴尬的问题,同样是拍照获取图片功能,在不同手机上运行的效果不一样,下面是在某型手机上测 ...

  4. C# 从类库中获取资源图片,把图片资源保存到类库中

    /// <summary> /// 获取资源图片 /// </summary> public class AssemblyHelper { #region 常量 /// < ...

  5. android把图片 视频 保存到相册

    //android把图片文件添加到相册 ContentResolver localContentResolver = getContentResolver(); ContentValues local ...

  6. 修正iOS从照相机和相册中获取的图片方向(转)

    - (UIImage *)fixOrientation { // No-op if the orientation is already correct if (self.imageOrientati ...

  7. 修正iOS从照相机和相册中获取的图片方向

    使用系统相机拍照得到的图片的默认方向有时不是ImageOrientationDown,而是ImageOrientationLeft,在使用的时候会出现图片顺时针偏转90°.使用fixOrientati ...

  8. 系统相册中获取gif图片 保证取到的图片不会改变

    NSURL *imageRefURL = [info valueForKey:UIImagePickerControllerReferenceURL];                         ...

  9. SWIFT中获取配置文件路径的方法

    在项目中有时候要添加一些配置文件然后在程序中读取相应的配置信息,以下为本人整理的获取项目配置文件(.plist)路径的方法: 1.获取沙盒路径后再APPEND配置文件 func documentsDi ...

随机推荐

  1. jquery、zepto冲突

    <script type="text/javascript" src="js/jquery.min.js"></script> < ...

  2. kubernetes 参考资料

    kubernetes 参考资料 非常建议先花20分钟,完成这个官方的交互式指南:https://kubernetes.io/docs/tutorials/kubernetes-basics/ 这个教程 ...

  3. LOJ tangjz的背包

    题目大意 有 \(n\) 个物品, 第 \(i\) 个物品的体积为 \(i\) 令 \(f(x)\) 为 选择 \(m\) 个物品, 体积和为 \(x\) 的方案数 令 \(V = \sum_{i=1 ...

  4. mysql 基本操作练习

    ), sex ), age )); , '北京'); , '上海'); , '广州'); , '北京'); , '北京'); , '上海'); , '北京'); #(). 写出sql语句,查询所有年龄 ...

  5. JAVA路线

    [转]Java自学之路——by马士兵 作者:马士兵老师 JAVA自学之路 一:学会选择 为了就业,不少同学参加各种各样的培训. 决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机. ...

  6. 【BZOJ2527】【POI2011】Meteors [整体二分]

    Meteors Time Limit: 60 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这个星球经常会下陨石雨.BI ...

  7. python面向对象之继承与派生

    一.继承 继承是一种创建新的类的方式,在python中,新建的类可以继承自一个或者多个父类,原始类称为基类或超类,新建的类称为派生类或子类. python中类的继承分为:单继承和多继承,如果是多继承的 ...

  8. CF#328 (Div. 2) C(大数)

    C. The Big Race time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. HTTP===http首部字段

    HTTP 首部字段 HTTP 首部字段是构成 HTTP 报文的要素之一.在客户端与服务器之间以 HTTP 协议进行通信的过程中,无论是请求还是响应都会使用首部字段,它能起到传递额外重要信息的作用. 使 ...

  10. 4.shell预定义变量

    就是shell设计者实现预定好的变量,可以直接在shell脚本中使用$$:当前进程的进程号(pid)$!:后台运行的最后一个进程的进程号(pid)$?:最后一次执行的命令的返回状态,如果这个变量的值为 ...