CGImageCreateWithMaskingColors返回nil

时间:2012-02-22 08:16:48

标签: objective-c

帮助!

我进行了广泛的搜索,但我还没有找到解决这个“简单”问题的方法。我试图做的是用alpha替换白色像素。看起来CGImageCreateWithMaskingColors应该给我我想要的东西,遗憾的是它在每种情况下都会返回nil。这是我的代码,我做错了什么?

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, colorSpace, kCGImageAlphaPremultipliedFirst);

//draw a black background
CGContextSetRGBFillColor(context,0,0, 0, 1);

CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));

char* text2 = (char *)[text cStringUsingEncoding:NSASCIIStringEncoding];

CGContextSelectFont(context, "Helvetica Bold", kFontSize, kCGEncodingMacRoman);

CGContextSetTextDrawingMode(context, kCGTextFill);

//draw text with the "alpha" color white)
CGContextSetRGBFillColor(context, 1, 1, 1, 1);

float textLength = 20;

CGContextShowTextAtPoint(context, (size.width/2)-(textLength/2), ((size.height/2)-(kFontSize/2))+5, text2, strlen(text2));

//create the black/white image

CGImageRef alphaMask = CGBitmapContextCreateImage(context);

const float colorMasking[6] = {0xEE, 0xFF, 0xEE, 0xFF, 0xEE, 0xFF};

CGImageRef imageMasked = CGImageCreateWithMaskingColors(alphaMask, colorMasking);
无论我尝试什么,

imageMasked都是nil。非常感谢您提供的任何帮助,谢谢!

0 个答案:

没有答案