iOS圖片加浮水印效果的實現並儲存至相冊

來源:互聯網
上載者:User

標籤:++   begin   net   傾斜   ddc   article   ios7   ios   htm   

圖片加浮水印效果的實現並儲存至相冊
實現效果

project下載:githubproject下載連結

代碼:

- (void)viewDidLoad {    [super viewDidLoad];    UIImage *image = [UIImage imageNamed:@"pushu.jpg"];    UIImage *waterImage = [self waterMarkImage:image withText:@"樸樹浮水印測試"];    UIImageWriteToSavedPhotosAlbum(waterImage, nil, nil, nil);  //儲存圖片至相冊//    展示圖片    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];    imageView.image = waterImage;    [self.view addSubview:imageView];    // Do any additional setup after loading the view, typically from a nib.}
- (UIImage *)waterMarkImage:(UIImage *)image withText:(NSString *)text {    UIGraphicsBeginImageContext(image.size);//    在畫布中繪製內容    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];//    繪製文字    [[UIColor darkGrayColor] set];    CGRect rect = CGRectMake(70, 220, 200, 60);    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:30],                          NSObliquenessAttributeName:@1};       //這裡設定了字型,和傾斜度。具體其它參數文章結尾有具體說明的文章連結    [text drawInRect:rect withAttributes:dic];    //在iOS7之前用下列方法比較方便//    [text drawInRect:rect withFont:[UIFont systemFontOfSize:30] lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter];//    從畫布中得到image    UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return returnImage;}
- (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs NS_AVAILABLE_IOS(7_0);

關於此方法,在iOS7以後應用。attrs設定參數的具體說明在例如以下連結文章中:
說明文章連結:attrs參數說明文章

iOS圖片加浮水印效果的實現並儲存至相冊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.