圖片添加浮水印效果

來源:互聯網
上載者:User

標籤:

  1. //建立一個UIImage對象
  2.     UIImage *image = [UIImage imageNamed:@"scene1.jpg"];
  3. //1.建立bitmap Context
  4.     UIGraphicsBeginImageContext(image.size);
  5. //2.把原圖繪製到context上
  6.     [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
  7. //3.把浮水印文字繪製到context上。
  8. //在左下角加浮水印
  9.     CGRect textFrame = CGRectMake(0, image.size.height-40, 200, 40);
  10. //設定浮水印文字屬性
  11.     UIFont *font = [UIFont boldSystemFontOfSize:30];
  12.     NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  13.     style.alignment = NSTextAlignmentCenter;
  14.     
  15.     UIColor *color = [UIColor colorWithRed:254.0/255 green:201.0/255 blue:21.0/255 alpha:1];
  16.     
  17.     [text drawInRect:textFrame withAttributes:
  18.      @{NSFontAttributeName:font,
  19.        NSForegroundColorAttributeName:color,
  20.        NSParagraphStyleAttributeName:style}];
  21. //4.從bitmap context上擷取加了浮水印以後的圖片。
  22.     UIImage *waterImage = UIGraphicsGetImageFromCurrentImageContext();
  23. //5.關閉bitmap context。
  24.     UIGraphicsEndImageContext();
  25. //6.返回擷取的圖片
  26.     return waterImage;
  27.  
  28.  
  29. 此方法最好獨立成一個單獨的類,只需一類方法就能完成。

圖片添加浮水印效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.