iOS : Save image with custom resolution

前端 未结 9 2027
长发绾君心
长发绾君心 2020-12-08 03:42

Hi I am try to capture a view then save as an image into Photo Library , but I need create a custom resolution for captured image , here is my code but when app saves the im

9条回答
  •  春和景丽
    2020-12-08 04:00

    #import 
    #import  
    
    + (UIImage *)resizeImage:(UIImage *)image toResolution:(int)resolution {
    NSData *imageData = UIImagePNGRepresentation(image);
    CGImageSourceRef src = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
    CFDictionaryRef options = (__bridge CFDictionaryRef) @{
                                                           (id) kCGImageSourceCreateThumbnailWithTransform : @YES,
                                                           (id) kCGImageSourceCreateThumbnailFromImageAlways : @YES,
                                                           (id) kCGImageSourceThumbnailMaxPixelSize : @(resolution)
                                                           };
    CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(src, 0, options);
    CFRelease(src);
    UIImage *img = [[UIImage alloc]initWithCGImage:thumbnail];
    return img;
    

    }

提交回复
热议问题