iOS : Save image with custom resolution

前端 未结 9 2025
长发绾君心
长发绾君心 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 03:59

    I think ALAssetRepresentation can help you.

    0 讨论(0)
  • 2020-12-08 04:00
    #import <ImageIO/ImageIO.h>
    #import <MobileCoreServices/MobileCoreServices.h> 
    
    + (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;
    

    }

    0 讨论(0)
  • 2020-12-08 04:01
    -(UIImage*)processImageRect:(UIImage*)image:(CGSize)sizeToForm {
        // Draw image1  
        UIGraphicsBeginImageContext(CGSizeMake(sizeToForm.width, sizeToForm.height));  
        [image drawInRect:CGRectMake(0.0, 0.0, sizeToForm.width, sizeToForm.height)]; 
        UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    
        return resultingImage;
    }
    

    Go with this may solve your issue.

    0 讨论(0)
提交回复
热议问题