在 iPhone 中的 UIImagePicker 中重新调整图像大小
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以从调整大小并居中裁剪图像找到答案。
I think you can find answer from resize and crop image centered.