InstagramPhotoPicker icon indicating copy to clipboard operation
InstagramPhotoPicker copied to clipboard

Photos showing in landscape

Open codeSupreme opened this issue 10 years ago • 9 comments

Some of the photos that I choose from the picker are displaying in landscape or wrong orientation.

codeSupreme avatar Apr 26 '15 02:04 codeSupreme

Sorry! This UI is not support landscape.

wenzhaot avatar Apr 27 '15 05:04 wenzhaot

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 .

codeSupreme avatar Apr 29 '15 23:04 codeSupreme

I am experiencing the same issue @codeSupreme. Were you able to fix it or have a workaround?

Thanks a lot

Krystel avatar May 16 '15 13:05 Krystel

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; }

andrewjaykeller avatar May 16 '15 19:05 andrewjaykeller

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 .

codeSupreme avatar May 16 '15 20:05 codeSupreme

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 !

Krystel avatar May 19 '15 08:05 Krystel

I also experienced this bug. @wenzhaot will you update your pods to fix this bug?

wlzch avatar Nov 25 '15 12:11 wlzch

Thanks @codeSupreme! Your solution fixed my problem! @wenzhaot try solution above it works at least for me and @Krystel. Best wishes!

ReFiRnE avatar Dec 21 '15 10:12 ReFiRnE

Thanks @codeSupreme!

red010182 avatar Apr 23 '16 16:04 red010182