How to easily resize/optimize an image size with iOS?

后端 未结 18 1407
温柔的废话
温柔的废话 2020-11-22 11:05

My application is downloading a set of image files from the network, and saving them to the local iPhone disk. Some of those images are pretty big in size (widths larger tha

18条回答
  •  轮回少年
    2020-11-22 11:48

    To resize an image I have better (graphical) results by using this function in stead of DrawInRect:

    - (UIImage*) reduceImageSize:(UIImage*) pImage newwidth:(float) pWidth
    {
        float lScale = pWidth / pImage.size.width;
        CGImageRef cgImage = pImage.CGImage;
        UIImage   *lResult = [UIImage imageWithCGImage:cgImage scale:lScale
                                orientation:UIImageOrientationRight];
        return lResult;
    }
    

    Aspect ratio is taken care for automatically

提交回复
热议问题