我是靠谱客的博主 热情发带,这篇文章主要介绍获取CGContextRef的几种方法,现在分享给大家,希望可以做个参考。

1.继承UIView,重写drawRect方法

CGContextRef ctx = UIGraphicsGetCurrentContext();

2.根据创建好的CALayer获取当前Layer的Context

- (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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部