当前位置: 移动技术网 > IT编程>开发语言>c# > Unity实现图片水印生成

Unity实现图片水印生成

2020年06月23日  | 移动技术网IT编程  | 我要评论
本文实例为大家分享了unity实现图片水印生成的具体代码,供大家参考,具体内容如下用于图片分享时添加logo水印的功能,之前用来做你画我猜的方法,核心是用texture2d中的setpixels方法具

本文实例为大家分享了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;
 }
 
 
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网