您当前的位置: 首页 >  unity
  • 4浏览

    0关注

    157博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity 压缩图片

牙膏上的小苏打2333 发布时间:2021-07-27 14:19:51 ,浏览量:4

🗜
  • 🌮Follow me

🌮Follow me
        /// 
        /// 等比例压缩(根据高度)
        /// 
        /// 
        /// 
        /// 
        public static Texture2D ScaleTexture(this Texture2D tex, int targetHeight) {
            int width = tex.width;
            int height = tex.height;
            float whratio = width * 1.0f / height;
            if (height > targetHeight)
            {
                height = targetHeight;
                width = (int)(height * whratio);
                Debug.Log($"重置宽高:{tex.width}_{tex.height} => {width}_{height}");
            }
            return tex.ScaleTexture(width,height);
        }
              /// 
        /// 压缩图片
        /// 
        /// 
        /// 
        /// 
        /// 
        public static Texture2D ScaleTexture(this Texture2D tex, int targetWidth, int targetHeight)
        {
            Texture2D res = new Texture2D(targetWidth, targetHeight, tex.format, true);
            Color[] pixels = res.GetPixels(0);
            float x = ((float)1 / tex.width) * ((float)tex.width / targetWidth);
            float y = ((float)1 / tex.height) * ((float)tex.height / targetHeight);
            for (int px = 0; px             
关注
打赏
1664520285
查看更多评论
0.0924s