简体   繁体   English

如何在不使用UIImageView的情况下缩小UIImage?

[英]How I can pinch zoom UIImage without using UIImageView?

I have UIImage and I want to scale it without setting it into UIImageView. 我有UIImage,我想缩放它而不将其设置为UIImageView。 How I can do that ? 我该怎么做?

As @rckoenes mentioned, UIImage is simply an image object, it does not handle display, which is precisely what UIImageView is for. 如@rckoenes所述,UIImage只是一个图像对象,它不处理显示,这正是UIImageView的用途。

For pinch zooming an image, the easiest way is to add a UIImageView as a subview to a UIScrollView . 为了缩小图像,最简单的方法是将UIImageView作为子视图添加到UIScrollView

If what you wanted was to change the size of your UIImage, I answered this here: set size of an image programatically 如果您想要更改UIImage的大小,我在这里回答了此问题: 以编程方式设置图像的大小

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM