-(CGImageRef)drawing{
CGContextRef context;
GLubyte *bitmapData;
size_t width, height;
width=super.size.width;
height=super.size.height;
bitmapData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
context = CGBitmapContextCreate(bitmapData, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if (context==NULL){
NSLog(@"context not created?! (o_*) ");
}
free(bitmapData);
CGContextSetRGBFillColor (context, 1, 0, 0, 1);
CGContextFillRect (context, CGRectMake (0, 0, 200, 100 ));
CGContextSetRGBFillColor (context, 0, 0, 1, .5);
CGContextFillRect (context, CGRectMake (0, 0, 100, 200 ));
CGImageRef myImage = CGBitmapContextCreateImage (context);
CGContextRelease(context);
return myImage;
}因此,我试图在上下文中渲染屏幕外的绘图,然后将其作为CGImageRef获取,但由于某些原因,上下文始终为空,并且当我读取图像输出时,应用程序崩溃。
有人能解释一下这是怎么回事吗?或者给我举个例子,说明这个方法是可行的。
发布于 2012-11-28 04:26:04
我不知道为什么上下文是空的-宽度和高度可能不好。
但是..。
Quartz 2D编程指南中有一个使用CGBitmapContextCreate的示例。
https://stackoverflow.com/questions/13590643
复制相似问题