I have UIImage and I want to scale it without setting it into UIImageView. How I can do that ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
As @rckoenes mentioned, UIImage is simply an image object, it does not handle display, which is precisely what UIImageView is for.
For pinch zooming an image, the easiest way is to add a UIImageView as a subview to a UIScrollView.
回答2:
If what you wanted was to change the size of your UIImage, I answered this here: set size of an image programatically
Simply do this:
// Given a UIImage image and a CGSize newSize:
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Your scaled image is now in newImage