Swift压缩图片以及修改图片颜色

Swift压缩图片以及修改图片颜色,第1张

概述extension UIImage { func scaleToSize(size:CGSize) -> UIImage { UIGraphicsBeginImageContextWithOptions(size, false, 0) self.draw(in: CGRect(x: 0, y: 0, width: size.width, height: si
extension UIImage {    func scaletoSize(size:CGSize) -> UIImage {        UIGraphicsBeginImageContextWithOptions(size,false,0)        self.draw(in: CGRect(x: 0,y: 0,wIDth: size.wIDth,height: size.height))        let img = UIGraphicsGetimageFromCurrentimageContext()        UIGraphicsEndImageContext()        return img!    }    func changecolor(color:UIcolor) -> UIImage {        UIGraphicsBeginImageContextWithOptions(self.size,self.scale)        let context = UIGraphicsGetCurrentContext()        context?.translateBy(x: 0,y: self.size.height)        context?.scaleBy(x: 1.0,y: -1.0)//kCGBlendModenormal        context?.setBlendMode(.normal)        let rect = CGRect(x: 0,wIDth: self.size.wIDth,height: self.size.height)        context?.clip(to: rect,mask: self.cgImage!);        color.setFill()        context?.fill(rect)        let newImage = UIGraphicsGetimageFromCurrentimageContext()        UIGraphicsEndImageContext()        return newImage!    }}
总结

以上是内存溢出为你收集整理的Swift压缩图片以及修改图片颜色全部内容,希望文章能够帮你解决Swift压缩图片以及修改图片颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1064399.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存