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

来源:互联网 发布:淘宝哪有买裸持照片的 编辑:程序博客网 时间:2024/04/28 10:13

以下只是简单的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)


0 0
原创粉丝点击