Unity實(shí)現(xiàn)圖片水印生成
本文實(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)文章
C# DataTable中Compute方法用法集錦(數(shù)值/字符串/運(yùn)算符/表等操作)
這篇文章主要介紹了C# DataTable中Compute方法用法,總結(jié)分析了DataTable中Compute方法常見的數(shù)值運(yùn)算操作、字符串操作、運(yùn)算符操作、表運(yùn)算等相關(guān)技巧,需要的朋友可以參考下2016-06-06
C# PC版微信消息監(jiān)聽自動(dòng)回復(fù)的實(shí)現(xiàn)方法
這篇文章主要介紹了C# PC版微信消息監(jiān)聽自動(dòng)回復(fù)的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
C#使用HttpWebRequest與HttpWebResponse模擬用戶登錄
這篇文章主要為大家詳細(xì)介紹了C#使用HttpWebRequest與HttpWebResponse模擬用戶登錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
向一個(gè)數(shù)組中插入一個(gè)1~100的隨機(jī)數(shù)
這篇文章主要介紹了如何向一個(gè)數(shù)組中插入一個(gè)1~100的隨機(jī)數(shù),思路很簡(jiǎn)單,需要的朋友可以參考下2014-07-07

