Unity實現(xiàn)圖片水印生成
更新時間:2020年04月18日 15:39:33 作者:liu_sanad
這篇文章主要為大家詳細介紹了Unity實現(xiàn)圖片水印生成,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Unity實現(xiàn)圖片水印生成的具體代碼,供大家參考,具體內(nèi)容如下
用于圖片分享時添加logo水印的功能,之前用來做你畫我猜的方法,核心是用Texture2D中的SetPixels方法
具體實現(xià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;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C# DataTable中Compute方法用法集錦(數(shù)值/字符串/運算符/表等操作)
這篇文章主要介紹了C# DataTable中Compute方法用法,總結(jié)分析了DataTable中Compute方法常見的數(shù)值運算操作、字符串操作、運算符操作、表運算等相關(guān)技巧,需要的朋友可以參考下2016-06-06
C# PC版微信消息監(jiān)聽自動回復(fù)的實現(xiàn)方法
這篇文章主要介紹了C# PC版微信消息監(jiān)聽自動回復(fù)的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
C#使用HttpWebRequest與HttpWebResponse模擬用戶登錄
這篇文章主要為大家詳細介紹了C#使用HttpWebRequest與HttpWebResponse模擬用戶登錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04

