图形开发绘图教程
2012-07-29 18:14
190 查看
iPhone图形开发绘图教程是本文要介绍的内容,介绍了很多关于绘图类的使用,先来看详细内容讲解。
1、绘图总结:
绘图前设置:
绘图后设置:
注: 画完图后,必须 先用CGContextStrokePath来描线,即形状,后用CGContextFillPath来填充形状内的颜色.
2.常见图形绘制:
3.常见控制方法:
4.创建内存图像context:
5.图形的变换:
6.常用函数:
7.从原图片中取小图.
8.屏幕快照:
合并两张bit图到一张image的方法
关键方法:
小结:iPhone图形开发绘图教程的内容介绍完了,希望本文对你有所帮助!
原文:http://wsqwsq000.iteye.com/blog/1317018
1、绘图总结:
绘图前设置:
CGContextSetRGBFillColor/CGContextSetFillColorWithColor //填充色 CGContextSetRGBStrokeColor/CGContextSetStrokeColorWithColor //笔颜色 CGContextSetLineWidth //线宽度
绘图后设置:
注: 画完图后,必须 先用CGContextStrokePath来描线,即形状,后用CGContextFillPath来填充形状内的颜色.
2.常见图形绘制:
CGContextFillRect/CGContextFillRects CGContextFillEllipseInRect CGContextAddRect/CGContextAddRects CGContextAddEllipseInRect CGContextAddLines CGContextMoveToPoint CGContextAddLineToPoint
3.常见控制方法:
CGContextSaveGState CGContextRestoreGState
4.创建内存图像context:
CGBitmapContextCreate <-----CGContextRlease释放 CGColorSpaceCreateWithName (KCGColorSpaceGenericRGB) CGColorSpaceRlease CGBitmapContextCreateImage() <-----CGImageRlease 释放. eg: CGContextRefMyCreateBitmapContext(intpixelsWide,intpixelsHigh) { CGContextRef context=NULL; CGColorSpaceRefcolorSpace; void* bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow =(pixelsWide*4); bitmapByteCount =(bitmapBytesPerRow*pixelsHigh); colorSpace=CGColorSpaceCreateDeviceRGB(); bitmapData=malloc(bitmapByteCount); if(bitmapData==NULL) { fprintf(stderr,"Memorynotallocated!"); returnNULL; } context=CGBitmapContextCreate(bitmapData, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if(context==NULL) { 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*screenshot =UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 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 *result = nil; unsignedchar *data = calloc(1,size.width*size.height*kBytesPerPixel); if (data != NULL) { // kCGImageAlphaPremultipliedLast 为预记录的#define value // 设置context上下文 CGContextRef context = CGBitmapContextCreate( data, size.width, size.height, 8, size.width*kBytesPerPixel, 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 imageRef = CGBitmapContextCreateImage(context); if (imageRef != NULL) { result = [UIImageimageWithCGImage:imageRef]; CGImageRelease(imageRef); } CGContextRelease(context); } free(data); } return result;
关键方法:
CGContextRef context = CGBitmapContextCreate(); CGContextTranslateCTM(); CGContextScaleCTM(); CGImageRef imageRef = CGBitmapContextCreateImage(context); CGImageRelease(imageRef);
小结:iPhone图形开发绘图教程的内容介绍完了,希望本文对你有所帮助!
原文:http://wsqwsq000.iteye.com/blog/1317018
相关文章推荐
- iPhone图形开发绘图教程
- Android OpenGL ES 简明开发教程三:3D绘图基本概念
- Android OpenGL ES 简明开发教程 03 <3D绘图基本概念>
- DirectX 9.0c游戏开发手记之RPG编程自学日志之9: Drawing with DirectX Graphics (用DirectX图形绘图)(第4节)(B)
- DirectX 9.0c游戏开发手记之RPG编程自学日志之10: Drawing with DirectX Graphics (用DirectX图形绘图)(第4节)(C)
- 多比图形控件(Web版)教程(一):基于Flex/Javascript的网页绘图控件
- 幻世(OurDream)2D图形引擎使用教程1——认识幻世,构建幻世开发环境
- [Qt教程] 第11篇 2D绘图(一)绘制简单图形
- Android官方开发文档Training系列课程中文版:OpenGL绘图之图形定义
- HTML5之Canvas绘图——使用Canvas绘制图形的基本教程
- 多比图形控件教程:基于Flex/Javascript的网页绘图控件
- Visual C++游戏开发笔记之四——游戏画面绘图(一)基本图形绘制
- Android简明开发教程十四:Context Menu 绘制几何图形
- DirectX 9.0c游戏开发手记之RPG编程自学日志之8: Drawing with DirectX Graphics (用DirectX图形绘图)(第4节)(A)
- Android简明开发教程十四:Context Menu 绘制几何图形
- iPhone图形开发绘图小结
- 【工业串口和网络软件通讯平台(SuperIO)教程】五.二次开发图形显示界面
- 【Visual C++】游戏开发笔记之四——游戏画面绘图(一)基本图形绘制
- iPhone图形开发绘图小结
- HTML5之Canvas绘图——使用Canvas绘制图形的基本教程