作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我需要在 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
的最新文档,
单击 Swift 链接,它显示:
func cropping(to rect: CGRect) -> CGImage?
关于 swift 3.0 : How to call CGImageCreateWithImageInRect()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38568288/
我是一名优秀的程序员,十分优秀!