是否有一种方法用指定的RGB颜色填充位图(上下文)?
这是我实施的程序:
-
为位图分配内存(malloc)
-
memset用零分配内存(得到黑色背景)
-
创建CGContextRef:
CGContextRef ctx = CGBitmapContextCreate(memData,width,height,8,bytesPerRow,colorSpace,bmpInfo)
- 插入图片:
CGContextDrawImage(ctx,CGRectMake(x,y,imgWidth,imgHeight),anotherImg)
- 完成图片:
CGImageRef createdImg = CGBitmapContextCreateImage(context)
从上面可以看出,背景总是黑色的 . 我希望能够为背景选择RGB颜色 . 怎么做的?
这适用于XCode中的OSX应用程序 .
我的函数是用C实现的,因为我对Objective C语法不太满意 .
1 回答
设置填充颜色(
CGContextSetFillColorWithColor
),然后填充整个上下文(CGContextFillRect
) .此外,您可能需要考虑将
NULL
作为data
参数传递给CGBitmapContextCreate
,这样您就不必担心它的内存管理 .