这篇文章主要为大家详细介绍了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;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
织梦狗教程
本文标题为:Unity实现图片水印生成


基础教程推荐
猜你喜欢
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- Unity shader实现高斯模糊效果 2023-01-16
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- C#中的Linq to JSON操作详解 2023-06-08
- C# 解析XML和反序列化的示例 2023-04-14
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- 实例详解C#实现http不同方法的请求 2022-12-26