我需要创建一个空的位图(在存储器中)与宽度和高度的已知值。 我将使用此位图的上下文在MKOverlayVew上绘制并显示图像。 有谁知道最简单的方法来做到这一点?iPhone:如何在内存中创建一个空位图?
0
A
回答
1
下面的代码应该做的伎俩。原籍:CGBitmapContextCreate on the iPhone/iPad
int width = 500;
int height = 500;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
memset(rawData, 0, height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
// Do your thing and then release
CGColorSpaceRelease(colorSpace);
free(rawData);
CGContextRelease(context);
我不知道是否有与贴在这个问题的代码有什么区别,但OP提到内存的问题,我从未有过任何与此代码我张贴。
空如在透明?或“空”,如填充一些背景颜色(黑色,白色等)? – hotpaw2 2011-05-16 19:12:13