The simplest way to resize an UIImage?

前端 未结 30 3207
迷失自我
迷失自我 2020-11-21 22:38

In my iPhone app, I take a picture with the camera, then I want to resize it to 290*390 pixels. I was using this method to resize the image :

UIImage *newI         


        
30条回答
  •  野性不改
    2020-11-21 23:05

    Why so complicated? I think using system API can achieve the same result:

    UIImage *largeImage;
    CGFloat ratio = 0.4; // you want to get a new image that is 40% the size of large image.
    UIImage *newImage = [UIImage imageWithCGImage:largeImage.CGImage
                                            scale:1/ratio
                                      orientation:largeImage.imageOrientation];
    // notice the second argument, it is 1/ratio, not ratio.
    

    The only gotcha is you should pass inverse of target ratio as the second argument, as according to the document the second parameter specifies the ratio of original image compared to the new scaled one.

提交回复
热议问题