Resize UIImage and change the size of UIImageView

后端 未结 7 992
梦谈多话
梦谈多话 2020-12-13 04:37

I have this UIImageView and I have the values of its max height and max width. What I want to achieve is that I want to take the image (with any aspect ratio an

相关标签:
7条回答
  • 2020-12-13 05:23
    - (UIImage *)image:(UIImage*)originalImage scaledToSize:(CGSize)size
    {
        //avoid redundant drawing
        if (CGSizeEqualToSize(originalImage.size, size))
        {
            return originalImage;
        }
    
        //create drawing context
        UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
    
        //draw
        [originalImage drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];
    
        //capture resultant image
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        //return image
        return image;
    }
    
    0 讨论(0)
提交回复
热议问题