利用CGContext简单的实现画圆画图片

这篇博客记录了在iOS开发中使用CGContext进行基本的画圆和绘制图片的操作,旨在帮助开发者回顾或了解这一不常用但重要的图形绘制技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下只是简单的context实现,因为不常用,所以记录一下

<span style="white-space:pre">	</span>let context = UIGraphicsGetCurrentContext()
//        圆
        /*
        CGContextAddArc(context, 200, 200, 100, 0, -3.141592653*2, 1)
        CGContextSetFillColorWithColor(context, UIColor.redColor().CGColor)
        CGContextFillPath(context)
        
        CGContextAddArc(context, 200, 200, 100, 0, -3.141592653*2, 1)
        CGContextSetLineWidth(context, 5)
        CGContextStrokePath(context)
        */
        
//        椭圆
        /*
        CGContextAddEllipseInRect(context, CGRect(x: 100, y: 400, width: 200, height: 100))
        CGContextSetFillColorWithColor(context, UIColor.redColor().CGColor)
        CGContextFillPath(context)
        
        CGContextAddEllipseInRect(context, CGRect(x: 100, y: 400, width: 200, height: 100))
        CGContextSetLineWidth(context, 5)
        CGContextStrokePath(context)
        */
        
//        画图片
//        先保存当前的状态
        CGContextSaveGState(context)
        CGContextTranslateCTM(context, 16, 480 + 84)
//        转换一下y轴
        CGContextScaleCTM(context, 1, -1)
        CGContextDrawImage(context, CGRect(x: 0, y: 0, width: 320, height: 480), UIImage(named: "1.png")?.CGImage)
        //        还原之前的状态
        CGContextRestoreGState(context)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值