如何删除图像周围的UIGraphicsGetCurrentContext而不是填充清除或更改上下文大小-Swift 4 UIGraphicsBeginImageContextWithOptions(开始ImageL.size,false,0.0) 让context=UIGraphicsGetCurrentContext()! startingImageL.draw(in:CGRect(原点:CGPoint.zero,大小:startingImageL.size),blendMode:.copy,alpha:1.0) context.setBlendMode(.copy) context.setFillColor(UIColor.clear.cgColor) 设rectPath=UIBezierPath(rect:CGRect(原点:CGPoint.zero,大小:startingImageL.size)) 设cropRectPath=UIBezierPath(rect:cropZone) 打印(“cropRectPath\(cropRectPath.debugDescription)”) 打印(“cropZone\(cropZone.debugDescription)”) 打印(“cropZone宽度\(cropZone.width)”) 打印(“cropZone高度\(cropZone.height)”) 打印(“cropZone maxX\(cropZone.maxX)”) 打印(“cropZone-maxY\(cropZone.maxY)”) rectPath.append(cropRectPath) rectPath.usesevenodfillrule=true context.saveGState() rectPath.fill() context.clip(到:cropZone) //UIRectClip(cropZone)
根据马特的建议,我所需要的只是推到负坐标,然后在那里开始图像!!因此,我所需要的(一旦你有了crop rect)是: 他的项目是如何删除图像周围的UIGraphicsGetCurrentContext而不是填充清除或更改上下文大小-Swift 4 UIGraphicsBeginImageContextWithOptions(开始ImageL.size,false,0.0) 让context=UIGraphicsGetCurrentContext()! startingImageL.draw(in:CGRect(原点:CGPoint.zero,大小:startingImageL.size),blendMode:.copy,alpha:1.0) context.setBlendMode(.copy) context.setFillColor(UIColor.clear.cgColor) 设rectPath=UIBezierPath(rect:CGRect(原点:CGPoint.zero,大小:startingImageL.size)) 设cropRectPath=UIBezierPath(rect:cropZone) 打印(“cropRectPath\(cropRectPath.debugDescription)”) 打印(“cropZone\(cropZone.debugDescription)”) 打印(“cropZone宽度\(cropZone.width)”) 打印(“cropZone高度\(cropZone.height)”) 打印(“cropZone maxX\(cropZone.maxX)”) 打印(“cropZone-maxY\(cropZone.maxY)”) rectPath.append(cropRectPath) rectPath.usesevenodfillrule=true context.saveGState() rectPath.fill() context.clip(到:cropZone) //UIRectClip(cropZone),swift,uiimage,core-graphics,uigraphicscontext,Swift,Uiimage,Core Graphics,Uigraphicscontext,根据马特的建议,我所需要的只是推到负坐标,然后在那里开始图像!!因此,我所需要的(一旦你有了crop rect)是: 他的项目是 谢谢你“收成很好”不,没有。你所做的一点也不差。请看我对这个问题的回答:这一个(可能更简单,更容易掌握什么是裁剪):嗯,好吧,让我来处理它,然后再回复你:欢迎DAnymore帮助。顺便说一句:)在我发布之前,我已经看过Matt的帖子,它帮助了我。。。但我想我错过了方向哈哈:D@matt是的,是你救了我我从没想过要从屏幕上开始!!非常感谢。 UIGraphicsBegi
谢谢你“收成很好”不,没有。你所做的一点也不差。请看我对这个问题的回答:这一个(可能更简单,更容易掌握什么是裁剪):嗯,好吧,让我来处理它,然后再回复你:欢迎DAnymore帮助。顺便说一句:)在我发布之前,我已经看过Matt的帖子,它帮助了我。。。但我想我错过了方向哈哈:D@matt是的,是你救了我我从没想过要从屏幕上开始!!非常感谢。
UIGraphicsBeginImageContextWithOptions(startingImageL.size, false, 0.0)
let context = UIGraphicsGetCurrentContext()!
startingImageL.draw(in: CGRect(origin: CGPoint.zero, size: startingImageL.size), blendMode: .copy, alpha: 1.0)
context.setBlendMode(.copy)
context.setFillColor(UIColor.clear.cgColor)
let rectPath = UIBezierPath(rect: CGRect(origin: CGPoint.zero, size: startingImageL.size))
let cropRectPath = UIBezierPath(rect: cropZone)
print("cropRectPath \(cropRectPath.debugDescription) ")
print("cropZone \(cropZone.debugDescription) ")
print("cropZone width \(cropZone.width) ")
print("cropZone height \(cropZone.height) ")
print("cropZone maxX \(cropZone.maxX) ")
print("cropZone maxY \(cropZone.maxY) ")
rectPath.append(cropRectPath)
rectPath.usesEvenOddFillRule = true
context.saveGState()
rectPath.fill()
context.clip(to: cropZone)
// UIRectClip(cropZone) <-nope
// UIRectFrame(cropZone) <- nope
// rectPath.addClip() <nope
UIGraphicsBeginImageContextWithOptions(cropZone.size, false, 0.0)
UIGraphicsGetCurrentContext()
startingImageL.draw(at: CGPoint(x:-cropZone.origin.x,
y:-cropZone.origin.y))
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()