How to crop the UIImage in iPhone?

前端 未结 3 1611
渐次进展
渐次进展 2020-12-17 08:23

In my application, I have set one image in UIImageView and the size of UIImageView is 320 x 170. but the size of original image is 320 x 460. so how to crop this image and d

3条回答
  •  半阙折子戏
    2020-12-17 08:30

    You can call this function for cropping the image -

    - (UIImage *)resizeImage:(UIImage *)oldImage width:(float)imageWidth height:(float)imageHeight {
        UIImage *newImage = oldImage;
    
        CGSize itemSize = CGSizeMake(imageWidth, imageHeight);
        UIGraphicsBeginImageContext(itemSize);
        CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
        [oldImage drawInRect:imageRect];
    
        newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return newImage;
    }
    

    this function returns the UIImage.

提交回复
热议问题