张运涛

c++

   :: 首页 :: 联系 :: 聚合  :: 管理

常用链接

留言簿(4)

搜索

  •  

最新评论

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:

CGContextRef MyCreateBitmapContext (int pixelsWide,int pixelsHigh)

{

CGContextRef    context = NULL;

CGColorSpaceRef colorSpace;

void *          bitmapData;

int             bitmapByteCount;

int             bitmapBytesPerRow;

bitmapBytesPerRow   = (pixelsWide * 4);

bitmapByteCount     = (bitmapBytesPerRow * pixelsHigh);

colorSpace = CGColorSpaceCreateDeviceRGB();

bitmapData = malloc( bitmapByteCount );

if (bitmapData == NULL)

{

fprintf (stderr, "Memory not allocated!");

return NULL;

}

context = CGBitmapContextCreate (bitmapData,     pixelsWide,     pixelsHigh,     8,     bitmapBytesPerRow,     colorSpace,     kCGImageAlphaPremultipliedLast);

if (context== NULL)

{

free (bitmapData);

fprintf (stderr, "Context not created!");

return NULL;

}

CGColorSpaceRelease( colorSpace );

return context;

}

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(); 

 

posted on 2010-08-11 14:39 张运涛 阅读(1236) 评论(0)  编辑 收藏 引用 所属分类: iphone

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理