UIImageView显示处理(圆角,变灰,uiimage放大)

转自:http://blog.csdn.net/cerastes/article/details/31736737


1.UIImageView圆角

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. CALayer *l = [cell.imgAvatarImage layer];     
  2. [l setMasksToBounds:YES];  
  3. [l setCornerRadius:6.0];  

2.UIImageView显示圆形

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. UIImageView *imageView1 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"image.png"]];  
  2.   
  3. imageView1.frame = CGRectMake(60,100100100);  
  4.   
  5. imageView1.layer.masksToBounds =YES;  
  6.   
  7. imageView1.layer.cornerRadius =50;  
  8.   
  9. [self.view addSubview:imageView1];  

3.UIImageView变灰效果

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. + (UIImage*)getGrayImage:(UIImage*)sourceImage  
  2. {  
  3.     int width = sourceImage.size.width;  
  4.     int height = sourceImage.size.height;  
  5.       
  6.     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();  
  7.     CGContextRef context = CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGImageAlphaNone);  
  8.     CGColorSpaceRelease(colorSpace);  
  9.       
  10.     if (context == NULL) {  
  11.         return nil;  
  12.     }  
  13.       
  14.     CGContextDrawImage(context,CGRectMake(00, width, height), sourceImage.CGImage);  
  15.     CGImageRef grayImageRef = CGBitmapContextCreateImage(context);  
  16.     UIImage *grayImage = [UIImage imageWithCGImage:grayImageRef];  
  17.     CGContextRelease(context);  
  18.     CGImageRelease(grayImageRef);  
  19.       
  20.     return grayImage;  
  21. }  

4 UIImage设置显示大小

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{  
  2.      UIGraphicsBeginImageContext(size);  
  3.          [img drawInRect:CGRectMake(00, size.width, size.height)];  
  4.         UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();  
  5.         // 使当前的context出堆栈  
  6.         UIGraphicsEndImageContext();  
  7.     // 返回新的改变大小后的图片  
  8.     return scaledImage;  
  9. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值