CGRect rect = CGRectMake(0, 0, 100, 100);
float white[1] = {0.0f};
float gray[1] = {1.0f};
CGContextSetFillColorSpace(bitmap, colorSpace);
CGContextSetFillColorWithColor(bitmap, CGColorCreate(colorSpace, white));
CGContextClearRect(bitmap, rect);
CGContextSetFillColorWithColor(bitmap, CGColorCreate(colorSpace, gray));
CGContextFillEllipseInRect(bitmap, rect);
CGImageRef imgRef = CGBitmapContextCreateImage(bitmap);
UIImage *image = [[[UIImage alloc] initWithCGImage:imgRef] autorelease];
self.imageView.image = image;
CGContextRelease(bitmap);
CGColorSpaceRelease(colorSpace);
代码在上面。它没有按我的预期工作。我对 iOS CoreGraphic 框架不熟悉。