![7795d9066fded88b399cf8e00efd0814.png](https://i-blog.csdnimg.cn/blog_migrate/9a9d86f64495f0bd57e5d9b167f83ab7.jpeg)
当使用unity开发过程中,需要用到图片压缩的时候,往往会不知所措,下面为压缩图片的算法,仅供参考:
public enum ImageFilterMode : int
{
Nearest = 0,
Biliner = 1,
Average = 2//最优
}
//压缩图片
public Texture2D ResizeTexture(Texture2D pSource, ImageFilterMode pFilterMode, Vector2 newSize)
{
//*** Variables
int i;
//*** Get All the source pixels
Color[] aSourceColor = pSource.GetPixels(0);
Vector2 vSourceSize = new Vector2(pSource.width, pSource.height);
//*** Calculate New Size
float xWidth = Mathf.RoundToInt(newSize.x);
float xHeight = Mathf.RoundToInt(newSize.y);
//*** Make New