I'm writing an app that takes an image and crops out everything except for a rectangle in the center of the image. (SWIFT) I can't get the crop function to work though. This is what I have now:
func cropImageToBars(image: UIImage) -> UIImage {
let crop = CGRectMake(0, 200, image.size.width, 50)
let cgImage = CGImageCreateWithImageInRect(image.CGImage, crop)
let result: UIImage = UIImage(CGImage: cgImage!, scale: 0, orientation: image.imageOrientation)
UIImageWriteToSavedPhotosAlbum(result, self, nil, nil)
return result
}
I've looked at a lot of different guides but none of them seem to work for me. Sometimes the image is rotated 90 degrees, I have no idea why it does that.