在iPhone中裁剪图像 [英] Cropping image in iPhone

查看:137
本文介绍了在iPhone中裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在UIImageView中裁剪图像。你能否为我提供对我有用的完整源代码。

I like to crop a image in UIImageView. Can you provide me the full source code that will helpful for me.

推荐答案

我曾经在同一个UIImageview中裁剪图像

I used to crop the image in same UIImageview

1)存储图像uiimageview

1)Store the image uiimageview

2)使用相同的uiimageview并将其存储为Uiimage

2)Take the same uiimageview and store it as Uiimage

3)裁剪图像并将其恢复

3)crop the image and restore it

以下代码将有所帮助

- (IBAction)setCropItem:(id)sender
{

-(IBAction)setCropItem:(id)sender {

UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finishedPicForCrop = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([finishedPicForCrop CGImage], CGRectMake(0, 45, 320, 420));
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef);
[firstImageView removeFromSuperview];
secondImageView = [[UIImageView alloc] initWithImage:img];
[secondImageView setFrame:CGRectMake(0, 0, 320, 460)];
scrollView.contentSize = secondImageView.bounds.size;
[scrollView addSubview:secondImageView];

}

这篇关于在iPhone中裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆