InstagramPhotoPicker
InstagramPhotoPicker copied to clipboard
Photos showing in landscape
Some of the photos that I choose from the picker are displaying in landscape or wrong orientation.
Sorry! This UI is not support landscape.
that is not what I am saying. I am saying that the picker is turning the image.
On Mon, Apr 27, 2015 at 1:13 AM, wenzhaot [email protected] wrote:
Sorry! This UI is not support landscape.
— Reply to this email directly or view it on GitHub https://github.com/wenzhaot/InstagramPhotoPicker/issues/11#issuecomment-96508990 .
I am experiencing the same issue @codeSupreme. Were you able to fix it or have a workaround?
Thanks a lot
The problem is that the images you are using were taken in portrait mode with the iPhone camera. This means that their UIImageOrientation is equal to right... You need to just rotate the image.. i.e. if your image is right then you need to rotate it 90 degrees. There are a ton of stack articles on this.
Here is what i do to properly orient images up no matter their input direction:
-
(UIImage *)imageRotate{ if (self.imageOrientation == UIImageOrientationUp) { return self; } CGAffineTransform transform = CGAffineTransformIdentity;
switch (self.imageOrientation) { case UIImageOrientationDown: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, self.size.width,self.size.height); transform = CGAffineTransformRotate(transform, M_PI); break;
case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: transform = CGAffineTransformTranslate(transform, self.size.width, 0); transform = CGAffineTransformRotate(transform, M_PI_2); break; case UIImageOrientationRight: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, 0, self.size.height); transform = CGAffineTransformRotate(transform, -M_PI_2); break; default: break;}
switch (self.imageOrientation) { case UIImageOrientationUpMirrored: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, self.size.width, 0); transform = CGAffineTransformScale(transform, -1, 1); break;
case UIImageOrientationLeftMirrored: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, self.size.height, 0); transform = CGAffineTransformScale(transform, -1, 1); break; default: break;}
// Now we draw the underlying CGImage into a new context, applying the transform // calculated above. CGContextRef ctx = CGBitmapContextCreate(NULL, self.size.width, self.size.height, CGImageGetBitsPerComponent(self.CGImage), 0, CGImageGetColorSpace(self.CGImage), CGImageGetBitmapInfo(self.CGImage)); CGContextConcatCTM(ctx, transform); switch (self.imageOrientation) { case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: case UIImageOrientationRight: case UIImageOrientationRightMirrored: // Grr... CGContextDrawImage(ctx, CGRectMake(0,0,self.size.height,self.size.width), self.CGImage); break;
default: CGContextDrawImage(ctx, CGRectMake(0,0,self.size.width,self.size.height), self.CGImage); break;}
CGImageRef cgimg = CGBitmapContextCreateImage(ctx); UIImage *newImage = [UIImage imageWithCGImage:cgimg]; return newImage; }
I was able to solve my issue. I am using the cocoa pod and the pod was not updated with the latest version of code. In particular this function in TWPhotoPickerController was not reflected in the cocoa pod.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
ALAsset * asset = [self.assets objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageWithCGImage:asset.defaultRepresentation.
fullResolutionImage scale:asset.defaultRepresentation.scale orientation:( UIImageOrientation)asset.defaultRepresentation.orientation];
[self.imageScrollView displayImage:image];
if (self.topView.frame.origin.y != 0) {
[self tapGestureAction:nil];
}
}
On Sat, May 16, 2015 at 9:06 AM, Krystel Chaccour [email protected] wrote:
I am experiencing the same issue @codeSupreme https://github.com/codeSupreme. Were you able to fix it or have a workaround?
Thanks a lot
— Reply to this email directly or view it on GitHub https://github.com/wenzhaot/InstagramPhotoPicker/issues/11#issuecomment-102624859 .
Thanks @pushtheworldllc and @codeSupreme It was actually the same problem @codeSupreme faced, I'm using pods as well. And updating "didSelectItemAtIndexPath" method solved it for me :) Thank you !
I also experienced this bug. @wenzhaot will you update your pods to fix this bug?
Thanks @codeSupreme! Your solution fixed my problem! @wenzhaot try solution above it works at least for me and @Krystel. Best wishes!
Thanks @codeSupreme!