unity texture2d 图片尺寸压缩

public static Texture2D TextureCut(Texture2D tex,float ratio = 0.8f)
    {
        if (tex == null)
            return null;
        if (ratio <= 0)
            return tex;
        Color color;
        int width = (int)(tex.width * ratio);
        int height = (int)(tex.height * ratio);
        Texture2D newTexture = new Texture2D(width,height, TextureFormat.RGB24, false);
        float newWidthGap = width * ratio;
        float newHieghtGap = height * ratio;
        for (int i = 0; i < newTexture.height; i++)
        {
            for (int j = 0; j < newTexture.width; j++)
            {
                color = tex.GetPixel((int)(j * (1 / ratio)), (int)(i * (1 / ratio)));
                newTexture.SetPixel(j, i, color);
            }
        }
        return newTexture;
    }

  

posted @ 2020-04-13 17:28  西湖盗月  阅读(3021)  评论(0编辑  收藏  举报