相关疑难解决方法(0)

如何在不损失视网膜显示质量的情况下将UIView捕获到UIImage

我的代码适用于普通设备,但在视网膜设备上会产生模糊图像.

有人知道我的问题的解决方案吗?

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}
Run Code Online (Sandbox Code Playgroud)

image-capture scale uikit uiimage retina-display

293
推荐指数
9
解决办法
15万
查看次数

使用抗锯齿为视网膜显示创建圆形或磁盘

我用CGContextFillEllipseInRectfrom 创建了一个圆圈CoreGraphic.

我正在使用这个圆圈(实际上是一个磁盘)来替换thumbImageUISlider.默认情况下应用抗锯齿.

但是我的iPhone 6上的结果显然不太好.我可以清楚地看到像素,而不是关闭抗锯齿,但比普通UISlider的像素更多.

也许我做错了什么.所以我的问题是,有没有办法以编程方式获得与UISlider默认使用的相同的漂亮磁盘?

编辑:

以下是我创建磁盘的方法:

class func drawDisk(rgbValue:UInt32, rectForDisk: CGRect = CGRectMake(0.0, 0.0, 1.0, 1.0)) -> UIImage {
    let color = uicolorFromHex(rgbValue)
    UIGraphicsBeginImageContext(rectForDisk.size)
    let context = UIGraphicsGetCurrentContext()

    CGContextSetFillColorWithColor(context, color.CGColor)
    CGContextFillEllipseInRect(context, rectForDisk)

    let rectForCircle = CGRectMake(0.5, 0.5, rectForDisk.size.width - 1, rectForDisk.size.height - 1)
    CGContextSetLineWidth(context, 1.0)
    CGContextSetStrokeColorWithColor(context,
            UIColor.blackColor().CGColor)
    CGContextAddEllipseInRect(context, rectForCircle)
    CGContextStrokePath(context)

    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return image
}
Run Code Online (Sandbox Code Playgroud)

core-graphics ios swift

2
推荐指数
1
解决办法
277
查看次数