gpt4 book ai didi

swift 3.0 : How to call CGImageCreateWithImageInRect()?

转载 作者:IT王子 更新时间:2023-10-29 05:22:30 24 4
gpt4 key购买 nike

我需要在 Swift 3.0 中实现这个 Objective-C 代码(我使用的是 Xcode 8 Beta 3):

// Note: this code comes from an Obj-C category on UIImage
CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, cropRect);
UIImage *image = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];

我在 CGImageCreateWithImageInRect() 的最新文档中找不到任何内容。

最佳答案

当我在 Xcode8 的 Swift 编辑器中编写这段代码时:

let imageRef = CGImageCreateWithImageInRect(self.CGImage!, cropRect)

Swift 向我展示了一个错误:

error: 'CGImageCreateWithImageInRect' has been replaced by instance method 'CGImage.cropping(to:)'

因此,我将行更改为:

let imageRef = self.cgImage!.cropping(to: cropRect)

而且您的代码的第二行似乎可以直接转换为 Swift:

let image = UIImage(cgImage: imageRef!, scale: self.scale, orientation: self.imageOrientation)

以及CGImageCreateWithImageInRect的最新文档,

CGImageCreateWithImageInRect

单击 Swift 链接,它显示:

func cropping(to rect: CGRect) -> CGImage?

关于 swift 3.0 : How to call CGImageCreateWithImageInRect()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38568288/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com