将CGPath导出为JPG或PNG [英] Export CGPath as JPG or PNG

查看:110
本文介绍了将CGPath导出为JPG或PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用CGPath在UIView中进行路径绘制,并将其导出为PNG?

Is it possible to take a path draw in an UIView with CGPath and export it as a PNG?

推荐答案

假设你想要一个UIImage,而不是一个png文件,你可以这样做:

Assuming you want a UIImage, not a png file, you can do something like this:

UIGraphicsBeginImageContext(size); 
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 2.0);
CGContextSetLineCap(context, kCGLineCapSquare);

//DRAW YOUR PATH HERE

CGContextStrokePath(context);

myUIImage = UIGraphicsGetImageFromCurrentImageContext();
[myUIImage retain];  

UIGraphicsEndImageContext();

这篇关于将CGPath导出为JPG或PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆