IOS第17天(1,Quartz2D图片水印)

****图片 水印

#import "HMViewController.h"

@interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. UIImage *oldImage = [UIImage imageNamed:@"img"]; // 开启上下文
// size 新的图片大小
// opaque YES 不透明 NO 透明
UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);
[oldImage drawAtPoint:CGPointZero]; NSString *text = @"我要高薪 !";
NSDictionary *dict = @{
NSFontAttributeName : [UIFont systemFontOfSize:],
NSForegroundColorAttributeName : [UIColor redColor] };
[text drawAtPoint:CGPointMake(, ) withAttributes:dict]; // 获取新的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); // 关闭上下文
UIGraphicsEndImageContext(); _imageView.image = newImage; // 把图片转换成png格式的二进制数据
NSData *data = UIImagePNGRepresentation(newImage); // 写入桌面
[data writeToFile:@"/Users/apple/Desktop/newImage.png" atomically:YES]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
上一篇:hdu 4681 string


下一篇:【转】 探索UDP套接字编程