在 XCODE 中简单地调整 UIImage 的大小 [英] Simple resizing of UIImage in XCODE
本文介绍了在 XCODE 中简单地调整 UIImage 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在尽可能少的行中调整 UIImage 的大小?我不介意比例,我只想将图像分辨率设置为 80x60.就这些
Is there any way how to resize UIImage in as few lines as possible? I don't mind of ratio, I just want to set image resolution to 80x60. That's all
推荐答案
这可能有点矫枉过正,但是,您可以简单地获取图像,并以您想要的分辨率创建图形上下文,然后您可以将 tempImage 设置为 UIImageView,覆盖它.
This may be overkill but, you can simply take your image, and create a graphics context at that resolution you want, then you can set the tempImage as the UIImageView, overwriting it.
UIImage *image = YourImageView.image;
UIImage *tempImage = nil;
CGSize targetSize = CGSizeMake(80,60);
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = CGRectMake(0, 0, 0, 0);
thumbnailRect.origin = CGPointMake(0.0,0.0);
thumbnailRect.size.width = targetSize.width;
thumbnailRect.size.height = targetSize.height;
[image drawInRect:thumbnailRect];
tempImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
YourImageView.image = tempImage;
这篇关于在 XCODE 中简单地调整 UIImage 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文