Tôi là hình ảnh mới trong Đồ họa cốt lõi và tôi cố vẽ hình tròn. Chúng có thể trong suốt (chỉ có nét) và đầy màu sắc nét. Vì vậy, phương pháp trông giống như sau:Hình ảnh đồ họa cốt lõi chất lượng thấp
+ (UIImage *)iconImageWithColor: (UIColor *)markColor strokeOnly:(BOOL)strokeOnly
{
CGRect rect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef clippingPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:7.5f].CGPath;
CGContextAddPath(context, clippingPath);
CGContextClip(context);
CGContextSetFillColorWithColor(context, strokeOnly == YES ? [[UIColor clearColor] CGColor] : [markColor CGColor]);
CGContextFillRect(context, rect);
CGPathRef path = CGPathCreateWithRoundedRect(rect, 10.f, 10.f, NULL);
[markColor setStroke];
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFillStroke);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Kết quả thật lạ - có vẻ như độ phân giải của hình ảnh rất thấp. Có thể làm cho hình ảnh kết quả có vẻ tốt trên màn hình võng mạc không?
Thêm dòng này trước khi vẽ trực tiếp: CGContextSetLineWidth (ngữ cảnh, 1.0); Bạn có thể cập nhật 1.0 theo yêu cầu của bạn. Chiều rộng đường vẽ của nó. – Mrunal