在 iPhone 中的 UIImagePicker 中重新调整图像大小

发布于 2024-10-06 04:29:24 字数 748 浏览 0 评论 0原文

我正在使用 UIImagePicker 从相机捕获图像。我的问题是我想使用自定义坐标重新调整图像大小。

因此,让我有一个用户可以在其中拍照的框架,我只想保存该框架区域。例如:如果我正在给一个人拍照,框架覆盖了他的脸,那么我只需要保存脸部区域而不是背景和身体的其他部分。

我正在使用的代码是: `

CGRect scaledRect = CGRectZero;

CGSize targetSize = CGSizeMake( baseImage.size.width,baseImage.size.height);

scaledRect.origin = CGPointMake(0, 0); 
scaledRect.size.width  = baseImage.size.width;
scaledRect.size.height =  baseImage.size.height;

UIGraphicsBeginImageContext(targetSize);    
[baseImage drawInRect:scaledRect];  

UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();    

return result;  

`

还有一个问题,我还需要担心设备方向吗?如果用户以横向模式拍照,我需要处理这个问题吗?

请建议

I am using UIImagePicker to capture image from camera. My problem is I want to re-size the image with custom coordinate.

So let I have frame in which user can take a picture and I want to save ONLY that frame area. Ex: if I am taking picture of a person the frame is covering his face then I just need to save the face area not the background the other body portion.

The code which I am using is :
`

CGRect scaledRect = CGRectZero;

CGSize targetSize = CGSizeMake( baseImage.size.width,baseImage.size.height);

scaledRect.origin = CGPointMake(0, 0); 
scaledRect.size.width  = baseImage.size.width;
scaledRect.size.height =  baseImage.size.height;

UIGraphicsBeginImageContext(targetSize);    
[baseImage drawInRect:scaledRect];  

UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();    

return result;  

`

One more question, Do I need to worry about device orientation too? If user is taking picture in landscape mode do I need to handle this?

Please suggest

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2024-10-13 04:29:25

我认为您可以从调整大小并居中裁剪图像找到答案。

I think you can find answer from resize and crop image centered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文