Plugins文件夹里放这三个
using System.IO;
/// <summary>
/// 保存替换贴图
/// </summary>
public class CameraTextureSave : MonoBehaviour
{
public static void SaveOne(WebCamTexture t,int frame,int w,int h)
{
Texture2D t2d= new Texture2D(w, h, TextureFormat.ARGB32, true);
Vector2 offset = new Vector2((t.width - w) / 2, (t.height - h) / 2);
t2d.SetPixels(t.GetPixels((int)offset.x, (int)offset.y, w, h));
t2d.Apply();
//编码
byte[] imageTytes=t2d.EncodeToJPG();
//存储
File.WriteAllBytes(@"Assets\Resources\myTexture1.jpg", imageTytes);
}
public static void SaveTwo(WebCamTexture t,int frame,int w=850,int h=550)
{
Texture2D texture=new Texture2D(w,h, TextureFormat.ARGB32,true);
Vector2 offset=new Vector2((t.width-w)/2,(t.height-h)/2);
texture.SetPixels(t.GetPixels((int)offset.x,(int)offset.y,w,h));
texture.Apply();
byte[] imageTytes = texture.EncodeToJPG();
File.WriteAllBytes(@"Assets\Resources\myTexture2.jpg", imageTytes);
}
}
using System.Collections;
using System.Collections.Generic<