码迷,mamicode.com
首页 > 移动开发 > 详细

ios 图片剪裁(代码)

时间:2014-10-09 02:48:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   ar   数据   sp   c   on   代码   

-(void)viewDidLoad

{  

  UIImage *oldImage = [UIImage imageNamed:@"new"];

  

   UIImage *oldImage = [UIImage imageNamed:@"new"];

   CGFloat centerX = oldImage.size.width/2;

  CGFloat centerY = oldImage.size.height/2;
   
  CGFloat radius = 30;

  //1.创建图形上下文

   UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);

  //2.获取图形上下文

   CGContextRef ref =UIGraphicsGetCurrentContext();

  //3.画一个圆

   CGContextAddArc(ref, centerX, centerY, radius,0, M_PI *2, 0);

  //4.剪切图片

   CGContextClip(ref);

  //5.获取当前的图片

  UIImage *newImage = UIGraphicsGetImageFromCurretImageContext();

  //6.结束图形上下文

  UIGraphicsEndImageContext();

  //7.获取数据

  NSData *data  = UIImagePNGRepresentation(newImge);

   [data writeToFile:@"/Users/apple/DeskTop/new1.png" atomically:YES];

  

}

ios 图片剪裁(代码)

标签:des   io   os   ar   数据   sp   c   on   代码   

原文地址:http://www.cnblogs.com/gtbo/p/4012156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!