1.图片截取
func test(addView:UIView) -> UIImage?{
UIGraphicsBeginImageContextWithOptions(CGSize(width: JY_DEVICE_WIDTH, height: addView.height), false, UIScreen.main.scale) if let context = UIGraphicsGetCurrentContext() {
addView.layer.render(in: context)
let imamge = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return imamge
}
return nil
}

  

2.保存相册
方法1:直接保存, 但是没办法做提示操作或错误监听
if let img = image{
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil)
} 方法2:可监听系统方法
if let img = self.test(addView: tempView){
UIImageWriteToSavedPhotosAlbum(img, self,#selector(image(image:didFinishSavingWithError:contextInfo:)), nil)
} //图片保存到本地
@objc func image(image:UIImage,didFinishSavingWithError error:NSError?,contextInfo:AnyObject) {
if error != nil
{
print("--\(image)---","++++\(String(describing: error))++++")
return
}else{
view.showSuccessInfo(info: "图片保存成功")
}
}

  

3.  保存的时候  
  (1)必须 重新创建一个临时tempView, 加到当前VC上,然后获取图片,保存到相册,
  (2)如果直接用VC的原来的self.view或者SV啥的, 没效果,不知道是啥问题
  (3)移除顺序, 先加到原来view上,在移除tempview let tempView = UIView()
tempView.bounds = CGRect(x: 0, y: 0, width: JY_DEVICE_WIDTH, height: scroller.contentSize.height)
view.addSubview(tempView)
configScroller(addView: tempView) if let img = self.test(addView: tempView){
UIImageWriteToSavedPhotosAlbum(img, self, #selector(image(image:didFinishSavingWithError:contextInfo:)), nil)
}else{
view.showTipsInfo(tips: "图片不存在")
}
//先添加到SV上在u移除, 不然子控件位置会 异常
configScroller(addView: scroller)
tempView.removeFromSuperview()

  

swift - 画图截取图片 - 保存相册的更多相关文章

  1. python从网络摄像头获取rstp视频流并截取图片保存

    import cv2 def get_img_from_camera_net(folder_path):     cap = cv2.VideoCapture("rtsp://admin:a ...

  2. Android--解决图片保存到相册显示1970年1月1日 8:00的问题

    import android.content.Context; import android.content.Intent; import android.database.Cursor; impor ...

  3. Android调用相册截取图片遇到的问题

    1.在Android中可以使用如下的方式来调用相册,选择图片进行裁剪使用,昨天在开发的时候遇到一个问题 private void cropBigImageUri(Uri uri, int output ...

  4. iOS9中将图片保存到照片中的某个相册的方法说明

    iOS9中将图片保存到照片中的某个相册的方法说明 在App中很经常遇到的就是用户点击某张图片后将图片保存到本地,下面介绍下iOS中保存图片的一些东西 1.首先,在iOS中把图片保存到系统照片是比较简单 ...

  5. iOS-iOS调用相机调用相册【将图片保存到本地相册】

    设置头部代理 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 1.调用相机 检测前置摄像头是否可用 - ...

  6. React Native之图片保存到本地相册(ios android)

    React Native之图片保存到本地相册(ios android) 一,需求分析 1,react native保存网络图片到相册,iOS端可以用RN自带的CameraRoll完美解决,但是andr ...

  7. 小程序图片保存的相册授权失败问题,原接口wx.openSeting()已经废弃了的解决办法

    项目中使用的是wepy框架开发的小程序,,, 使用场景是,用户点击下载图片的时候,要调起授权button(小程序拉起授权的功能都集成在了button组件,所以这里需要用到button组件里的一个ope ...

  8. android将应用中图片保存到系统相册并显示

    我应用到的场景是程序中在视频通讯时截图,将截图保存到本地相册中 /*** @param bmp 获取的bitmap数据 * @param picName 自定义的图片名*/ public static ...

  9. [RN] React Native 图片保存到相册(支持 Android 和 ios)

    React Native 图片保存到相册(支持 Android 和 ios) 原理: IOS用 RN自带的 CameraRoll, Android 使用 不成功,需要 react-native-fs  ...

随机推荐

  1. 4:list 列表

    list:列表.数组.array . list 是有序的,list的定义以 [] 为标识.如:list1 = ['name1', 'name2', 'name3'] 元素可以是任何类型的,如字符串.数 ...

  2. java script删除数组的方法集合(转载)

    一.清空数组 var ary = [1,2,3,4]; ary.splice(0,ary.length);//清空数组 console.log(ary); // 输出 [],空数组,即被清空了 二.删 ...

  3. 【374】Adobe Acrobat 操作技巧

    1. 文件内容增减 参考:如何在PDF文件中删除页面 参考:如何旋转.移动.删除和重新编号 PDF 页面 双击PDF文档,并在预览程序中打开它. 如果在其他程序(如Adobe Reader)中打开文档 ...

  4. 使用adb查看CPU和内存

    adb shell ->cat/sys/class/net/wlan0/address 获取Mac地址 abd shell –>cat /proc/cpuinfo 获取CPU信息 adb ...

  5. Android Studio 上传GitHub项目失败后的一些问题

    在Android Studio上传项目到GitHub时候多上传了了一些项目,想删除,但是报诸如 Remote project is already on GitHub 一些乱七八糟的问题,而且,提示p ...

  6. java解决查找问题

    1.给定一个字符串,找到里面的大写字母和小写字母以及其他字母的个数: 代码: package test; public class Stringclass { public static void m ...

  7. 学JS的心路历程 -函式(三)this

    this是什么,取决于被呼叫的呼叫地点. 昨天有提到说,呼叫函式时候会传递隐含参数:arguments和this并讲解了arguments,今天我们就来探讨this吧! 什么是this 我们都会呼叫函 ...

  8. struts原理图

    n the diagram, an initial request goes to the Servlet container (such as Jetty or Resin) which is pa ...

  9. php mysql 查询判断周几

    $where .= " and (DAYOFWEEK( from_unixtime(`px_time`, '%Y-%m-%d')) = 1)";  //周日从1开始

  10. 安装scrapy框架

    前提安装好python.setuptools. 1.安装Python 安装完了记得配置环境,将python目录和python目录下的Scripts目录添加到系统环境变量的Path里.在cmd中输入py ...