The simplest way to resize an UIImage?

前端 未结 30 2653
迷失自我
迷失自我 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 22:47

    I found a category for UIImage in Apple's own examples which does the same trick. Here's the link: https://developer.apple.com/library/ios/samplecode/sc2273/Listings/AirDropSample_UIImage_Resize_m.html.

    You'll just have to change the call:

    UIGraphicsBeginImageContextWithOptions(newSize, YES, 2.0);
    

    in imageWithImage:scaledToSize:inRect: with:

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 2.0);
    

    In order to consider the alpha channel in the image.

提交回复
热议问题