You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
861 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UC
{
public class TextureUtil
{
public static Texture2D Resize(Texture tex, float downScaleRatio)
{
RenderTexture temp = RenderTexture.GetTemporary((int)(tex.width / downScaleRatio), (int)(tex.height / downScaleRatio), 0, RenderTextureFormat.ARGB32);
Graphics.Blit(tex, temp);
RenderTexture current = RenderTexture.active;
RenderTexture.active = temp;
Texture2D newTex = new Texture2D(temp.width, temp.height, TextureFormat.ARGB32, false);
newTex.ReadPixels(new Rect(0, 0, temp.width, temp.height), 0, 0);
newTex.Apply();
RenderTexture.active = current;
RenderTexture.ReleaseTemporary(temp);
return newTex;
}
}
}