欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)圖片水印生成

 更新時(shí)間:2020年04月18日 15:39:33   作者:liu_sanad  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)圖片水印生成,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)圖片水印生成的具體代碼,供大家參考,具體內(nèi)容如下

用于圖片分享時(shí)添加logo水印的功能,之前用來做你畫我猜的方法,核心是用Texture2D中的SetPixels方法

具體實(shí)現(xiàn)如下

效果圖:

上代碼,比較簡(jiǎn)單不多說了

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
public class WaterMarkAdd : MonoBehaviour {
 public Image targetImage;
 public Sprite logoSprite;
 public Sprite imageSprite;
 // Use this for initialization
 void Start () {
 Texture2D t = AddLogo(imageSprite.texture, logoSprite.texture);
 Sprite s = new Sprite();
 s=Sprite.Create(t, new Rect(0,0,t.width, t.height),new Vector2(0.5f,0.5f));
 targetImage.sprite = s;
 }
 
 private Texture2D AddLogo(Texture2D image,Texture2D logo)
 {
 Texture2D logoTexture = new Texture2D(image.width,image.height);
 Color[] colors = image.GetPixels();
 for (int i = 0; i < logo.width; i++)
 {
  for (int j = 0; j < logo.height; j++)
  {
  Color c = logo.GetPixel(i, j); 
 
  if (c.a != 0)
  {
   colors[logoTexture.width * j + i] = c;
  }
  
  }
 }
 logoTexture.SetPixels(0, 0, image.width, image.height, colors);
 logoTexture.Apply();
 return logoTexture;
 }
 
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論