I'm using Xcode 6.0.1 with Swift. I have a UIImage, and I would like to make another image using the old image as a source, with the new image being rotated in some way... say flipped vertically.
This question was already answered a few months ago. However, that solution doesn't work for me, even though the situation is identical.
When I have
var image = UIImage(CGImage: otherImage.CGImage, scale: 1.0, orientation: .DownMirrored)
Xcode complains that there's an "Extra argument 'scale' in call". After checking with the Apple documentation, this makes no sense, as that version of the initializer does take those three arguments. Leaving out the scale and orientation arguments does fix the problem, but prevents me from doing the rotation.
The only other reference to this that I can find is this guy, who had the same problem.
What do you think?
I do need this to run on this version of Xcode, so if there's an alternate way to perform the rotation (I haven't found one yet) that would be useful.
'Extra argument in call' generally happens when one of the input types is incorrect.
You can fix your code with
Check this:
Do not use
UIGraphicsBeginImageContext
because it will destroy the quality of your vector, useUIGraphicsBeginImageContextWithOptions
. This is my implementation in Swift 3/4:For Swift 4.2
Swift 3:
Rotating to right:
Tested in Playground:
This works for iOS 8+ and maintains the image quality. It's two extensions for UIImage.