我是靠谱客的博主 神勇水池,这篇文章主要介绍Unity实现图片水印生成,现在分享给大家,希望可以做个参考。

本文实例为大家分享了Unity实现图片水印生成的具体代码,供大家参考,具体内容如下

用于图片分享时添加logo水印的功能,之前用来做你画我猜的方法,核心是用Texture2D中的SetPixels方法

具体实现如下

效果图:

上代码,比较简单不多说了

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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实现图片水印生成内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(391)

评论列表共有 0 条评论

立即
投稿
返回
顶部