0

I have the portrait version working fine as the scale is 0.75. But I cannot get the landscape to work correctly. I am using UIImagePickerController.

        // Landscape

        // Full landscape image is width: 3264 and height 2448

        CGRect cropped = CGRectMake(306.0, 0.0, 1836.0, 2448.0);

        CGImageRef imageRef = CGImageCreateWithImageInRect ([photo CGImage], cropped);
        // UIImage * croppedPhoto = [UIImage imageWithCGImage: imageRef];
        UIImage * croppedPhoto = [UIImage imageWithCGImage:imageRef scale:photo.scale orientation:UIImageOrientationUp];
        CGImageRelease (imageRef);

        // Scale the photo down
        CGRect rect = CGRectMake(0.0, 0.0, 450.0, 600.0);
        UIGraphicsBeginImageContext( rect.size );
        [croppedPhoto drawInRect:rect];
        picture = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }

I have the following issues:

  1. I want the edges cut off to make the landscape into a portrait (the center part of the landscape needs to be converted to portrait).

  2. Depending on which way I hold the device, the image is either upside down or correct.

What am I doing wrong?

cdub
  • 24,555
  • 57
  • 174
  • 303
  • I guess you are not handling the UIImage rotation here, see this article http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/. It might help you to get things perfect. – iphonic Jul 15 '14 at 07:11
  • If this is all you are trying to do I suggest you to use an UIImageView, put the image on, set content mode to scale aspect fill and create a screenshot. If you need a few more things such as rotations crete an UIView and put the image view on it then create a screenshot of the UIView. I know it sound stupid but the code that will be behind it is almost the same as you would write it. UIView's already have all this logic. – Matic Oblak Jul 15 '14 at 07:16
  • @iphonic is Trevor's code still legit even tho it was written in 2009? (like I am on ios 7.1) – cdub Jul 15 '14 at 07:26
  • @chris Yes it works fine. See few comments here http://stackoverflow.com/questions/6141298/how-to-scale-down-a-uiimage-and-make-it-crispy-sharp-at-the-same-time-instead/7775470#7775470 posted around `2013`. – iphonic Jul 15 '14 at 08:42
  • i'm using it with ContentModes and it's still not scaling correctly for landscape on my iphone 4s – cdub Jul 16 '14 at 04:37
  • i want it to crop the sides off the image in landscape and make it portrait which it doesn't do for me. Either AspectFill or Fit give me the same result – cdub Jul 16 '14 at 04:39

0 Answers0