从本地加载大图,经过双线性采样生成小图:
public Texture2D GenerateThumbnail(string path, int width, int height)
{
//加载原图
byte[] fileData = System.IO.File.ReadAllBytes(path);
Texture2D source = new Texture2D(1, 1);
source.LoadImage(fileData);
//采样
Texture2D thumbnail = new Texture2D(width, height);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
float percentX = (float)x / width;
float percentY = (float)y / height;
Color newColor = source.GetPixelBilinear(percentX, percentY);
thumbnail.SetPixel(x, y, newColor);
}
}
thumbnail.Apply();
return thumbnail;
}