1.继承UIView,重写drawRect方法
复制代码
1CGContextRef ctx = UIGraphicsGetCurrentContext();
2.根据创建好的CALayer获取当前Layer的Context
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30- (CGContextRef) MyCreateBitmapContext:(CALayer*)layer { int pixelsWide = layer.bounds.size.width; int pixelsHigh = layer.bounds.size.height; CGContextRef context = NULL; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4);// 1 bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); context = CGBitmapContextCreate (NULL,// 4 pixelsWide, pixelsHigh, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context== NULL) { return NULL; } CGColorSpaceRelease( colorSpace );// 6 return context;// 7 }
可供扩展:
http://www.cocoabuilder.com/archive/cocoa/218456-drawing-an-nsimage-in-calayer.html
http://www.cocoachina.com/bbs/read.php?tid-43635.html
http://www.freeboxgame.com/freebox/technologyCampQuestion.aspx?questionid=56
http://www.cocoachina.com/bbs/m/read.php?tid=51704#read
最后
以上就是热情发带最近收集整理的关于获取CGContextRef的几种方法的全部内容,更多相关获取CGContextRef内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复