ios - 如何放大和缩放uiimage

标签 ios uiimage

我不熟悉在 Xcode 中裁剪图像,在我的应用程序中我拍了一张照片,然后将该照片放入圆圈形式的 uiimage 中。我想要做的是在图像处于圆形 View 时放大或移动图像,然后将其保存到最终的 uiimage 中。到目前为止我所拥有的是

CALayer *imageLayer= imageView.layer;
imageView.layer.cornerRadius =imageView.frame.size.height/2;
[imageLayer setBorderWidth:.5];
[imageLayer setMasksToBounds:YES];
[self.view addSubview:imageView];

请尽快帮忙!我很困惑。

最佳答案

以下代码使用缩放参数 scaleyour_imagerect 矩形创建子图像

CGImageRef imageRef = CGImageCreateWithImageInRect([your_image CGImage], rect);
UIImage *subImage = [UIImage imageWithCGImage:imageRef scale:scale orientation:your_image.imageOrientation];
CGImageRelease(imageRef);

关于ios - 如何放大和缩放uiimage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22312451/

相关文章:

android - 在 iOS 上带有 expo 的 react-native statusBar

ios - 在以前的 iOS 版本上测试

swift 4 : nil loading local UIImage

ios - 为什么 cornerRadius 给我一个菱形?

ios - UIImage 在将其转换为 CIImage,然后转换为 CGImage 并返回 UIImage 时失去了方向

iPhone - 一次弹出多个表单

ios - 如何在 swift 上制作这样的 firebase 列表

ios - RNDecryptor addData 方法中的混淆

iphone - 使动态 ImageView 可点击

ios - 用另一种颜色替换 uiimage 中的颜色