iPhone图形开发绘图小结
1、绘图总结:
绘图前设置:
- CGContextSetRGBFillColor/CGContextSetFillColorWithColor??//填充色? ?
- CGContextSetRGBStrokeColor/CGContextSetStrokeColorWithColor?//笔颜色? ?
- CGContextSetLineWidth???//线宽度??
绘图后设置:
注:? 画完图后,必须 先用CGContextStrokePath来描线,即形状,后用CGContextFillPath来填充形状内的颜色.
2.常见图形绘制:
- CGContextFillRect/CGContextFillRects? ?
- CGContextFillEllipseInRect? ?
- CGContextAddRect/CGContextAddRects? ?
- CGContextAddEllipseInRect? ?
- CGContextAddLines? ?
- CGContextMoveToPoint? ?
- CGContextAddLineToPoint??
3.常见控制方法:
- CGContextSaveGState? ?
- CGContextRestoreGState??
4.创建内存图像context:
- CGBitmapContextCreate???????<CGColorSpaceRlease? ?
- CGBitmapContextCreateImage()???<eg:? ?
- CGContextRefMyCreateBitmapContext(intpixelsWide,intpixelsHigh)? ?
- {? ?
- CGContextRef????CGColorSpaceRefcolorSpace;? ?
- void*??????????bitmapData;? ?
- int?????????????bitmapByteCount;? ?
- int?????????????bitmapBytesPerRow;? ?
- if(fprintf(stderr,"Memorynotallocated!");? ?
- returnNULL;? ?
- }? ?
- if(free(bitmapData);? ?
- fprintf(stderr,"Contextnotcreated!");? ?
- returnNULL;? ?
- }? ?
- CGColorSpaceRelease(colorSpace);? ?
- returncontext;? ?
- }??
5.图形的变换:
- CGContextTranslateCTM? ?
- CGContextRotateCTM? ?
- CGContextScaleCTM??
6.常用函数:
- ??CGRectContainsPoint();? ?
- CGRectContainsRect();? ?
- CGRectIntersectsRect();? ?
- CGRectIntersection();? ?
- CGPointEqualToPoint();? ?
- CGSizeEqualToSize();??
7.从原图片中取小图.
- CGImageCreateWithImageInRect??
8.屏幕快照:
- #import?"QuartzCore/QuartzCore.h"? ?
- ?
- UIGraphicsBeginImageContext(yourView.frame.size);? ?
- [[yourView?layer]?renderInContext:UIGraphicsGetCurrentContext()];? ?
- UIImage*from:http://www.cppblog.com/zhangyuntaoshe/articles/123066.html??
合并两张bit图到一张image的方法
- To?graphically?merge?two?images?into?a?new?image,?you?do?something?like?this:? ?
- UIImage?*unsignedchar?*//?kCGImageAlphaPremultipliedLast?为预记录的#define?value? ?
- //?设置context上下文? ?
- CGContextRef?CGColorSpaceCreateDeviceRGB(),?kCGImageAlphaPremultipliedLast);? ?
- if?(context?!=?NULL)?{? ?
- UIGraphicsPushContext(context);? ?
- //??Image?为下载的背景图片,用于比较context? ?
- CGContextTranslateCTM(context,?0,?size.height);? ?
- CGContextScaleCTM(context,?1,?-1);? ?
- [image?drawInRect:imageRect];? ?
- [image2?drawInRect:image2Rect];? ?
- UIGraphicsPopContext();? ?
- CGImageRef?if?(imageRef?!=?NULL)?{? ?
- CGImageRelease(imageRef);? ?
- }? ?
- CGContextRelease(context);? ?
- }? ?
- free(data);? ?
- }? ?
- return?result;??
关键方法:?
- CGContextRef?CGContextScaleCTM();? ?
- CGImageRef?CGImageRelease(imageRef);?
小结:iPhone图形开发绘图教程的内容介绍完了,希望本文对你有所帮助!