【发布时间】:2013-09-10 18:04:17
【问题描述】:
目前,我在绘制小点时遇到了图形问题。
我注意到在大多数专业日历应用程序中,事件日历标识符是一个小点,其颜色是事件日历颜色。
我在我的应用程序中需要画一个更好的点。这是我的意思的照片。
这里可能不明显,但是当它在我的手机上时,彩色圆点非常像素化。我想去除像素化。
我浏览了 Ray Wenderlich 网站上的一个教程:Ray Wenderlich Core Graphics。
这是我画点的结果:
UIGraphicsBeginImageContext(cell.imageViewPic.bounds.size);
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]);
CGContextFillEllipseInRect(contextRef,(CGRectMake (0.f, 0.f, cell.imageViewPic.bounds.size.width, cell.imageViewPic.bounds.size.height)));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
cell.imageViewPic.image = image;
所以这实际上实现了圆,但我添加了它以在圆周围画一条小线以消除像素化但不行。
CGPoint startPoint = CGPointMake(cell.imageViewPic.frame.origin.x, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height - 1);
CGPoint endPoint = CGPointMake(cell.imageViewPic.frame.origin.x + cell.imageViewPic.frame.size.width - 1, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height - 1);
UIColor* color = [UIColor blackColor];
CGContextSaveGState(contextRef);
CGContextSetLineCap(contextRef, kCGLineCapSquare);
CGContextSetStrokeColorWithColor(contextRef, color.CGColor);
CGContextSetLineWidth(contextRef, 10.0);
CGContextMoveToPoint(contextRef, startPoint.x + 0.5, startPoint.y + 0.5);
CGContextAddLineToPoint(contextRef, endPoint.x + 0.5, endPoint.y + 0.5);
CGContextStrokePath(contextRef);
CGContextRestoreGState(contextRef);
整体看起来像这样......
UIGraphicsBeginImageContext(cell.imageViewPic.bounds.size);
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]);
CGContextFillEllipseInRect(contextRef,(CGRectMake (0.f, 0.f, cell.imageViewPic.bounds.size.width, cell.imageViewPic.bounds.size.height)));
CGPoint startPoint = CGPointMake(cell.imageViewPic.frame.origin.x, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height - 1);
CGPoint endPoint = CGPointMake(cell.imageViewPic.frame.origin.x + cell.imageViewPic.frame.size.width - 1, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height - 1);
UIColor* color = [UIColor blackColor];
CGContextSaveGState(contextRef);
CGContextSetLineCap(contextRef, kCGLineCapSquare);
CGContextSetStrokeColorWithColor(contextRef, color.CGColor);
CGContextSetLineWidth(contextRef, 10.0);
CGContextMoveToPoint(contextRef, startPoint.x + 0.5, startPoint.y + 0.5);
CGContextAddLineToPoint(contextRef, endPoint.x + 0.5, endPoint.y + 0.5);
CGContextStrokePath(contextRef);
CGContextRestoreGState(contextRef);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
cell.imageViewPic.image = image;
圆圈仍在绘制,但没有绘制“笔划”。
如果有人能就如何解决这个像素化问题提供一些指示,请发帖!
【问题讨论】:
-
如果您使用 100% 大小的视网膜模拟器,像素化将在模拟器中可见。
标签: ios objective-c core-graphics cgcontext