本文整理汇总了C#中UnityEngine.Texture2D.Trim方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.Trim方法的具体用法?C# Texture2D.Trim怎么用?C# Texture2D.Trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.Trim方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Capture
private IEnumerator Capture () {
if(videoframe < framesToCapture) {
string name =System.String.Format("{0}/{1:D04} sprite.png", realFolder, videoframe );//Time.frameCount
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D texb = new Texture2D(width, height, TextureFormat.RGB24, false);
texb.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texb.Apply();
yield return 0;
yield return new WaitForEndOfFrame();
Texture2D texw = new Texture2D(width, height, TextureFormat.RGB24, false);
texw.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texw.Apply();
Texture2D outputtex = new Texture2D(width, height, TextureFormat.ARGB32, false);
for (int y = 0; y < outputtex.height; ++y) {
for (int x = 0; x < outputtex.width; ++x) {
var alpha = texw.GetPixel(x, y).r - texb.GetPixel(x, y).r;
alpha = 1.0f - alpha;
Color color = Color.clear;
if(alpha != 0) {
color = texb.GetPixel(x, y) / alpha;
}
color.a = alpha;
outputtex.SetPixel(x, y, color);
}
}
Texture2D tex=outputtex.Trim(padding);
textures.Add(tex);
tex.SaveTexture(name);
Destroy(texb);
Destroy(texw);
videoframe++;
}
else {
EditorApplication.isPlaying=false;
done=true;
}
}