PHIMageManager requestImageDataForAsset:options:resultHandler: does not take into account orientation

371 Views Asked by At

I am trying to use this method to then upload imageData to my service but the resulting imageData does not take into account orientation and I am uploading images in the incorrect orientation.

Any suggestions?

1

There are 1 best solutions below

0
Red Mak On

I solve the exact same problem using this f°, to get the original image size, you just have to pass size == CGSizeMake (10000000000, 10000000000), hope this help :)

+ (UIImage *)createThumbFromImageIO:(UIImage*)image maxPixelSize:(CGSize)size
{
    NSData *imagedata = UIImageJPEGRepresentation(image, 1);
    CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imagedata, NULL);

    if (!imageSource) return nil;

    CGSize imageSize = image.size;

    imageSize = CGSizeMake(size.width,size.height);

    CFDictionaryRef options = (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
                                                         (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailWithTransform,
                                                         (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailFromImageIfAbsent,
                                                         (id)[NSNumber numberWithFloat:imageSize.height], (id)kCGImageSourceThumbnailMaxPixelSize,
                                                         nil];

    CGImageRef imgRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options);

    image = [UIImage imageWithCGImage:imgRef];

    CGImageRelease(imgRef);

    CFRelease(imageSource);
    return image;
}