iphone中模糊图片的指定区域的兑现
iphone中模糊图片的指定区域的实现
在iOS开发中会遇到模糊图片的,这里给大家介绍一个可以模糊掉图片指定区域的防范,原文:http://ask.****.net/questions/1002
更多解决方案也请看上边链接

设置UIImageView的属性名字为:imageView,然后同一序列添加下面四个方法到实现文件中,然后设置ImageViewMode为Redraw,添加模糊效果的UIImage自定义或默认类,就OK了。
method 1 - 剪裁图片
Method 2 -
Method 3 - 圆角矩形
在iOS开发中会遇到模糊图片的,这里给大家介绍一个可以模糊掉图片指定区域的防范,原文:http://ask.****.net/questions/1002
更多解决方案也请看上边链接
设置UIImageView的属性名字为:imageView,然后同一序列添加下面四个方法到实现文件中,然后设置ImageViewMode为Redraw,添加模糊效果的UIImage自定义或默认类,就OK了。
method 1 - 剪裁图片
#pragma mark - Croping the Image
- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect{
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
Method 2 -
#pragma mark - Marge two Images
- (UIImage *) addImageToImage:(UIImage *)img withImage2:(UIImage *)img2 andRect:(CGRect)cropRect{
CGSize size = CGSizeMake(imageView.image.size.width, imageView.image.size.height);
UIGraphicsBeginImageContext(size);
CGPoint pointImg1 = CGPointMake(0,0);
[img drawAtPoint:pointImg1];
CGPoint pointImg2 = cropRect.origin;
[img2 drawAtPoint: pointImg2];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
Method 3 - 圆角矩形
#pragma mark - RoundRect the Image
- (UIImage *)roundedRectImageFromImage:(UIImage *)image withRadious:(CGFloat)radious {
if(radious == 0.0f)
return image;
if( image != nil) {
CGFloat imageWidth = image.size.width;
CGFloat imageHeight = image.size.height;
CGRect rect = CGRectMake(0.0f, 0.0f, imageWidth, imageHeight);
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
const CGFloat scale = window.screen.scale;
UIGraphicsBeginImageContextWithOptions(rect.size, NO, scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSaveGState(context);
CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (context, radious, radious);
CGFloat rectWidth = CGRectGetWidth (rect)/radious;
CGFloat rectHeight = CGRectGetHeight (rect)/radious;