iOS : Save image with custom resolution

前端 未结 9 2045
长发绾君心
长发绾君心 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:50

    First get your image in UIImage object. Create your size what ever you want and use following..

    UIImage *image = // you image;
    CGSize size;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
    ([UIScreen mainScreen].scale == 2.0)) {
    
         // RETINA DISPLAY
          size = CGSizeMake(640, 640);
    }
    else {
         // Non Ratina device
          size = CGSizeMake(320, 320);
    }
    
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    

    Now you will get destImage with new resolution.

    Hope this is what you are looking for :)

提交回复
热议问题