一直想写博客,现在先从一些简单的开始吧!
图片的颜色反转,原理就是用白色的rgb值减去当前图片颜色rgb值,得到后的效果就是反转后的颜色。
unity中代码如下
//将图片颜色反转
public Texture2D TransparentColor(Texture2D img) {
Texture2D copyImge = new Texture2D(img.width, img.height);
copyImge.SetPixels(img.GetPixels());
copyImge.Apply();
for (int h = 0; h < copyImge.height; h++) {
for (int w = 0; w < copyImge.width; w++) {
float r =1- copyImge.GetPixel(w,h).r;float g =1- copyImge.GetPixel(w, h).g;
float b =1-copyImge.GetPixel(w, h).b;
copyImge.SetPixel(w,h, new Color(r, g, b));
}
copyImge.Apply();
}
return copyImge;
}
如有错误,欢迎指出!!