最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS 圖片裁剪 + 旋轉(zhuǎn)

 更新時(shí)間:2017年03月09日 09:29:26   作者:Silence_cnblogs  
之前分別介紹了圖片裁剪和圖片旋轉(zhuǎn)的方法,裁剪和旋轉(zhuǎn)是可以連在一起執(zhí)行的。本文將對(duì)此進(jìn)行介紹,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

之前分別介紹了圖片裁剪和圖片旋轉(zhuǎn)方法

《iOS 圖片裁剪方法》

地址:http://www.fzitv.net/article/107308.htm

《iOS 圖片旋轉(zhuǎn)方法》

地址:http://www.fzitv.net/article/107361.htm

裁剪和旋轉(zhuǎn)是可以連在一起執(zhí)行的。先定位到需要裁剪的區(qū)域,然后以此區(qū)域的中心為軸,旋轉(zhuǎn)一定角度,最后獲取旋轉(zhuǎn)后此區(qū)域內(nèi)的圖片??梢杂梦粓D(Bitmap)繪制實(shí)現(xiàn)

static func cropImage(_ image: UIImage, withRect rect: CGRect, angle: Double) -> UIImage? {
 // Creates a bitmap-based graphics context with rect size
 // and makes it the current context
 UIGraphicsBeginImageContext(rect.size)
 // Get current graphics context
 guard let context = UIGraphicsGetCurrentContext() else { return nil }
 // Move context origin to rect center
 context.translateBy(x: rect.width / 2, y: rect.height / 2)
 // Convert angle to radian and rotate
 context.rotate(by: CGFloat(angle / 180 * M_PI))
 // Move context origin back (-rect.width / 2, -rect.height / 2)
 // and move opposite direction of rect origin (-rect.minX, -rect.minY)
 context.translateBy(x: -rect.width / 2 - rect.minX, y: -rect.height / 2 - rect.minY)
 // Draw image at context origin
 image.draw(at: .zero)
 // Get image
 let finalImage = UIGraphicsGetImageFromCurrentImageContext()
 // Removes the current bitmap-based graphics context from the top of the stack
 UIGraphicsEndImageContext()
 // Return image
 return finalImage
}

rect為需要裁剪的區(qū)域,采用原圖的坐標(biāo)系。angle為需要旋轉(zhuǎn)的角度,單位是度,正值表示圖片順時(shí)針?lè)较蛐D(zhuǎn)。具體實(shí)現(xiàn)的講解見(jiàn)注釋。

最后的圖片可能超出原圖區(qū)域,超出部分為透明。

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

文山县| 祁阳县| 深圳市| 昔阳县| 湘乡市| 平昌县| 冷水江市| 乌鲁木齐市| 衡水市| 大庆市| 新民市| 瑞安市| 松溪县| 唐河县| 建瓯市| 广德县| 葫芦岛市| 宜阳县| 贵溪市| 灵宝市| 永定县| 平泉县| 和田市| 红安县| 香河县| 乐陵市| 神池县| 开江县| 双鸭山市| 慈溪市| 思茅市| 铜陵市| 吴忠市| 新昌县| 阿拉善左旗| 漾濞| 陆河县| 塔河县| 长顺县| 石景山区| 慈利县|