根據untiy的 Sexpixel 方法 先獲取原圖的像素點顏色 寫入到新的texture2D上 下面示範是將一張1920*1080的圖 重寫爲384+216的圖 縮小1/5
public Texture2D t2d;
Texture2D texture = new Texture2D(384, 216, TextureFormat.RGBA32, true);
for (int i = 0; i < texture.height; i++)//壓縮圖片
{
for (int j = 0; j < texture.width; j++)
{
Color color = t2d.GetPixel(j * 5, i * 5);
texture.SetPixel(j, i, color);
}
}
texture.Apply();
byte[] imagesst = texture.EncodeToJPG();
File.WriteAllBytes(filepathsst + "/" + lengthpicCam.ToString() + ".jpg", imagesst);