首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIImage 3 3Transform

UIImage 3 3Transform
EN

Stack Overflow用户
提问于 2015-11-26 13:07:56
回答 1查看 121关注 0票数 0

我如何从图像中转换图像以使其看起来像图像?只是想了解使用UIImage的扩展来旋转im的转换是如何工作的,但这只是暂时的,只是新的

代码语言:javascript
复制
public func imageRotatedByDegrees(degrees: CGFloat, flip: Bool) -> UIImage {
    let radiansToDegrees: (CGFloat) -> CGFloat = {
        return $0 * (180.0 / CGFloat(M_PI))
    }
    let degreesToRadians: (CGFloat) -> CGFloat = {
        return $0 / 180.0 * CGFloat(M_PI)
    }

    // calculate the size of the rotated view's containing box for our drawing space
    let rotatedViewBox = UIView(frame: CGRect(origin: CGPointZero, size: size))
    let t = CGAffineTransformMakeRotation(degreesToRadians(degrees));
    rotatedViewBox.transform = t
    let rotatedSize = rotatedViewBox.frame.size

    // Create the bitmap context
    UIGraphicsBeginImageContext(rotatedSize)
    let bitmap = UIGraphicsGetCurrentContext()

    // Move the origin to the middle of the image so we will rotate and scale around the center.
    CGContextTranslateCTM(bitmap, rotatedSize.width / 2.0, rotatedSize.height / 2.0);

    //   // Rotate the image context
    CGContextRotateCTM(bitmap, degreesToRadians(degrees));

    // Now, draw the rotated/scaled image into the context
    var yFlip: CGFloat

    if(flip){
        yFlip = CGFloat(-1.0)
    } else {
        yFlip = CGFloat(1.0)
    }

    CGContextScaleCTM(bitmap, yFlip, -1.0)
    CGContextDrawImage(bitmap, CGRectMake(-size.width / 2, -size.height / 2, size.width, size.height), CGImage)

    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return newImage
}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-26 13:18:35

您将需要使用核心动画与CATransform3D,并调整转换给一个深刻的印象。您要做的是将一个小的负值(-1/200是一个很好的起点)应用到转换矩阵的M34组件中。您可以对每个视图的层进行以太处理,或者在超级层上使用CATransformLayer,然后将其他图像添加为转换层的子层。

这是棘手的,挑剔的东西。我已经有一段时间没有搞砸了,所以我已经不记得细节了,但是这应该足够让你开始了。我建议在"iOS透视图“、"M34”和"CATransformLayer“中搜索更多内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33939555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档