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;
    }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM