相关疑难解决方法(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万
查看次数

如何在Swift中使用全屏截图?

我发现了这段代码:

func screenShotMethod() {
    //Create the UIImage
    UIGraphicsBeginImageContext(view.frame.size)
    view.layer.renderInContext(UIGraphicsGetCurrentContext())
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    //Save it to the camera roll
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
Run Code Online (Sandbox Code Playgroud)

我需要做些什么才能将所有其他元素(如导航栏)添加到屏幕截图中?

screenshot uiimage ios swift

64
推荐指数
6
解决办法
6万
查看次数

如何在Swift中绘制图像?

我需要能够以编程方式绘制图像,并保存该图像供以后使用.比如说,在图像上的特定x和y坐标上画一条线,保存图像,并将其显示在一个简单的视图控制器上.我将如何在Swift中执行此操作?(最好是Swift 2,我还在开发中并且没有将我的mac更新到Sierra)

更新:可能与将UIImage转换为CGLayer,绘制它,然后将其转换回UIImage有关.

xcode core-graphics ios swift

18
推荐指数
5
解决办法
2万
查看次数

如何使用 Swift 在 UIImageView 中绘制平滑的线条?

下面的代码在 UIImageView 上绘制点之间的直线。绘图渲染速度快,看起来不错,但可能会更好,所以我想修改代码以创建平滑的曲线。在过去的六周里,我在 Swift 中研究了许多示例,但成功率为零。

我必须修改以下代码的哪些部分(以及如何)来实现这一点?有人告诉我调用下面的代码片段而不是 CGContextAddLineToPoint() (在下面的 // 2 处)应该可以解决问题,但我不清楚如何调用它以及它如何与当前代码完全相关。

片段:

func drawQuadLineWithPoints(firstPoint: CGPoint, secondPoint: CGPoint, thirdPoint: CGPoint, inContext: CGContext) {
    CGContextMoveToPoint(context, 0.5 * (firstPoint.x + secondPoint.x), 0.5 * (firstPoint.y + secondPoint.y));
    CGContextAddQuadCurveToPoint(context, secondPoint.x, secondPoint.y, 0.5 * (secondPoint.x + thirdPoint.x), 0.5 * (secondPoint.y + thirdPoint.y));
}
Run Code Online (Sandbox Code Playgroud)

代码:

  override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    swiped = false
    if let touch = touches.anyObject() as? UITouch {
      lastPoint = touch.locationInView(self.view)
    }
  }

  func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {

    // 1 …
Run Code Online (Sandbox Code Playgroud)

smooth draw uiimageview swift

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