LoginSignup
0
0

More than 5 years have passed since last update.

NSImageを反転させるextension

Last updated at Posted at 2017-03-18

自分用メモ

NSImage+Flip.swift

extension NSImage {

    func flipHorizontal() {
        let flipper = NSAffineTransform()
        let dimensions = self.size
        self.lockFocus()

        flipper.scaleX(by: -1, yBy: 1)
        flipper.concat()

        self.draw(at: NSPoint(x: -dimensions.width, y: 0), from: NSMakeRect(0,0, dimensions.width, dimensions.height), operation: .copy, fraction: 1)
        self.unlockFocus()
    }

    func flipVartical() {
        let flipper = NSAffineTransform()
        let dimensions = self.size
        self.lockFocus()

        flipper.scaleX(by: 1, yBy: -1)
        flipper.concat()

        self.draw(at: NSPoint(x: 0, y: -dimensions.height), from: NSMakeRect(0,0, dimensions.width, dimensions.height), operation: .copy, fraction: 1)
        self.unlockFocus()
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0