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