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

ios 图片水印 (代码)

时间:2014-10-09 13:27:13      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   sp   c   on   log   代码   r   

-(void)viewDidLoad

{

    //1.1背景图片

  UIImage *bgImage  [UIImage imageNamed:@"new"];

  CGFloat w = bgImage.size.width;

  CGFloat h = bgImage.size.width;

  //1.创建图形上下文

  UIGraphicsBeginImageContextWithOptions(bgImage.size,NO,0.0);

    //1.2.画图

  [bgImage drawInRect:CGRectMake(0,0,w,h)];

  //2.创建水印图片

  UIImage *iconImage = [UIImage imageNamed:@"logo"];

  CGFloat iconW = iconImage.size.width * 0.2;

  CGFloat iconH = iconImage.size.height *0.2;

  CGFloat iconX = w - iconW - 5;

  CGFloat iconY = h - iconH - 5;

  //2.1画图

  [iconImage drawInRect:CGRectMake(iconX,iconY,iconW,iocnH)];

  //3.获取当前的图片

  UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

  //4.结束图形

  UIGraphicsEndImageContext();

  self.imageView.image = newImage;

  //5.打印

  NSData *data = UIImagePNGRepresentation(newImage);

  [data writeToFile:@"/User/apple/DeskTop/new.png" atomically:YES];

}

ios 图片水印 (代码)

标签:des   io   os   sp   c   on   log   代码   r   

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

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