0

我正在尝试在视网膜@2x 显示器上创建一条 3 像素宽的线。简单的想法是创建一条 1.5 宽的线:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0.0f);
CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(aRef, NO);
CGContextSetShouldAntialias(aRef, NO);
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
[bezierPath moveToPoint: CGPointMake(10, 0)];
[bezierPath addLineToPoint: CGPointMake(10, 10)];
bezierPath.lineWidth = 1.5;
[bezierPath stroke];
UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但最后,我在屏幕上得到了 4 像素的线宽。

问题是,我使用的是 iPad 3(所以视网膜 @2x),当我使用带有预定义系统按钮 UIBarButtonSystemItemAdd 的 UIBarButtonItem 时,十字的两条路径在我的屏幕上是 3 像素宽度。

4

2 回答 2

0

它适用于:

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(13, 21, 18, 1.5)];
于 2014-11-08T09:26:37.200 回答
0

我怀疑这是 b/c 你的路径是 1.5 点,但从 (0,0) 开始。由于路径在路径的一侧绘制了一半,在另一侧绘制了一半,这意味着在路径上方/下方绘制了 0.75 分。

这意味着您的路径从(以 px 为单位)到达:

left:   (-1.5, 0) =>  (-1.5, 10) 
center: (0,0)     =>  (0,10) 
right:  (1.5,0)   =>  (1.5,10)

这意味着每一面都将使用 2 个像素进行渲染。

相反,您可能希望从 (.5, 0) => (.5, 10) 创建线,这会将路径宽度与屏幕上的像素对齐:

left:   (-1, 0) =>  (-1, 10) 
center: (.5, 0) =>  (.5, 10) 
right:  (2,  0) =>  (2,  10)
于 2014-11-08T00:00:19.950 回答