我的代码适用于普通设备,但在视网膜设备上会产生模糊图像.
有人知道我的问题的解决方案吗?
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Run Code Online (Sandbox Code Playgroud) 我发现了这段代码:
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)
我需要做些什么才能将所有其他元素(如导航栏)添加到屏幕截图中?
我需要能够以编程方式绘制图像,并保存该图像供以后使用.比如说,在图像上的特定x和y坐标上画一条线,保存图像,并将其显示在一个简单的视图控制器上.我将如何在Swift中执行此操作?(最好是Swift 2,我还在开发中并且没有将我的mac更新到Sierra)
更新:可能与将UIImage转换为CGLayer,绘制它,然后将其转换回UIImage有关.
下面的代码在 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) swift ×3
ios ×2
uiimage ×2
draw ×1
scale ×1
screenshot ×1
smooth ×1
uiimageview ×1
uikit ×1
xcode ×1