CGContextAddArc画圆的使用(附CGContext画图基本过程)


最近老画圆,所以对CGContextAddArc的接触比较多。

CGContextAddArc(Context, CGFloat x , CGFloat y, CGFloat radius, CGFloat startAngle , CGFloat endAngle, int clockwise);

这个方法牛人门都很熟悉了,我只是记录我自己的。

关于角度,由x,y可确定圆心坐标,而0,0角度位于圆心的正下方。

startAngle是由0,0偏移的。

偏移方向是由clockwise控制的,0为顺时针,1为逆时针。


 

iPhone中双缓冲的实现

原理不复杂:

  1. 创建一个bitmap context

  2. 在bitmap context上画东西

  3. 通过bitmap context生成一个CGImage

  4. 通过UIImage把CGImage内容画到屏幕上

  示例代码:

  // create the bitmap context

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

  CGContextRef context = CGBitmapContextCreate(nil,27,27,8,0, colorSpace,kCGImageAlphaPremultipliedLast);

  CFRelease(colorSpace);

  // create an arrow image

  // set the fill color

  CGColorRef fillColor = [[UIColor blackColor] CGColor];

  CGContextSetFillColor(context, CGColorGetComponents(fillColor));

  CGContextBeginPath(context);

  CGContextMoveToPoint(context, 8.0f, 13.0f);

  CGContextAddLineToPoint(context, 24.0f, 4.0f);

  CGContextAddLineToPoint(context, 24.0f, 22.0f);

  CGContextClosePath(context);

  CGContextFillPath(context);

  // convert the context into a CGImageRef

  CGImageRef image = CGBitmapContextCreateImage(context);

  CGContextRelease(context);

  UIImage* image2 = [UIImage imageWithCGImage:image];

  [image2 drawInRect:CGRectMake(0, 0, 120, 160)];

  其中对context绘图的部分可以用来画耗时的3d动画等。



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM