ios - 从选定区域中的 uiimagepickerviewcontroller 裁剪图像
<p><p>如何在捕获图像时从选定区域中的 <code>UIImagePickerController</code> 裁剪图像。覆盖 View 到 <code>UIImagePickerController</code></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>代码下方</p>
<pre><code>-(UIImage *)centerCropImage:(UIImage *)image
{
// Use smallest side length as crop square length
CGFloat squareLength = MIN(image.size.width, image.size.height);
// Center the crop area
CGRect clippedRect = CGRectMake((image.size.width - squareLength) / 2, (image.size.height - squareLength) / 2, squareLength, squareLength);
// Crop logic
CGImageRef imageRef = CGImageCreateWithImageInRect(, clippedRect);
UIImage * croppedImage = ;
CGImageRelease(imageRef);
return croppedImage;
}
</code></pre>
<p>之后在 imagePickerViewDelegate 方法中</p>
<pre><code>-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = ;
; //Just give your image here for cropping
yourImage.image=image;
picker.delegate =self;
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 从选定区域中的 uiimagepickerviewcontroller 裁剪图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26628169/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26628169/
</a>
</p>
页:
[1]