Unity实现图片水印生成
更新时间:2020年04月18日 15:39:33 作者:liu_sanad
这篇文章主要为大家详细介绍了Unity实现图片水印生成,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Unity实现图片水印生成的具体代码,供大家参考,具体内容如下
用于图片分享时添加logo水印的功能,之前用来做你画我猜的方法,核心是用Texture2D中的SetPixels方法
具体实现如下
效果图:

上代码,比较简单不多说了
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;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
C# DataTable中Compute方法用法集锦(数值/字符串/运算符/表等操作)
这篇文章主要介绍了C# DataTable中Compute方法用法,总结分析了DataTable中Compute方法常见的数值运算操作、字符串操作、运算符操作、表运算等相关技巧,需要的朋友可以参考下2016-06-06
C#使用HttpWebRequest与HttpWebResponse模拟用户登录
这篇文章主要为大家详细介绍了C#使用HttpWebRequest与HttpWebResponse模拟用户登录,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-04-04


最新评论