首页 > 解决方案 > UIImage中的图像在绘制时调整大小

问题描述

当我将图像加载到我的 UIImageView 并想在上面画画时。然后会改变图像的比例。有人可以告诉我这里出了什么问题吗?

谢谢

绘图前

绘图前

当你画

当你画

func drawLines(fromPoint:CGPoint,toPoint:CGPoint) {
    UIGraphicsBeginImageContext(self.view.frame.size)
    imageView.image?.draw(in: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))

    let context = UIGraphicsGetCurrentContext()

    context?.move(to: CGPoint(x: fromPoint.x, y: fromPoint.y))
    context?.addLine(to: CGPoint(x: toPoint.x, y: toPoint.y))

    context?.setBlendMode(CGBlendMode.normal)
    context?.setLineCap(CGLineCap.round)
    context?.setLineWidth(brushSize)
    context?.setStrokeColor(UIColor(red: red, green: green, blue: blue, alpha: opacityValue).cgColor)

    context?.strokePath()

    imageView.image = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()
}

标签: iosswiftuiimageviewuiimage

解决方案


推荐阅读