大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > IOS技巧 > ios 图片水印 (代码)

ios 图片水印 (代码)

关键词:水印代码图片ios  阅读(747) 赞(13)

[摘要]本文是对ios 图片水印 (代码)的讲解,对学习IOS苹果软件开发有所帮助,与大家分享。

-(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];

}



相关评论