PHIMageManager requestImageDataForAsset:options:resultHandler:不考虑方向

时间:2016-09-06 16:18:31

标签: ios alasset phasset

我正在尝试使用此方法然后将imageData上传到我的服务,但生成的imageData没有考虑到方向,我正在以错误的方向上传图片。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我使用这个f°解决了完全相同的问题,要获得原始图像大小,你只需要传递大小== CGSizeMake(10000000000,10000000000),希望这个帮助:)

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