0

所以我有以下代码:

 CGContextDrawImage(context, CGRectMake(100, 0, 220, self.image.size.height), self.image.CGImage);

基本上,我要求 CG 将图像向右绘制 100 像素。现在效果很好。但是在图像的左侧,我看到了一个白色背景。如何将此背景更改为其他颜色?说我想要一个黑色的背景

4

1 回答 1

4

在绘制图像之前,用所需的颜色填充矩形:

CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextFillRect(context, CGRectMake(0, 0, self.image.size.width + 100, self.image.size.height)); //I suppose your rect's width is as much as image's width +100
//Then draw your image
CGContextDrawImage(context, CGRectMake(100, 0, 220, self.image.size.height), self.image.CGImage);

注意:确保您绘制的矩形宽度至少是图像的宽度 + 100

于 2012-06-05T20:59:12.320 回答