14

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()

4

2 に答える 2

36

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)

コードの 2 行目は、Swift に直接変換できるようです。

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

の最新のドキュメントCGImageCreateWithImageInRect

CGImageCreateWithImageInRect

Swift リンクをクリックすると、次のように表示されます。

func cropping(to rect: CGRect) -> CGImage?
于 2016-07-25T13:09:55.817 に答える