伊景轩

unity 生成缩略图 , 图片缩放

public static Texture2D Resize(Texture2D source, int newWidth, int newHeight)
{
    source.filterMode = FilterMode.Point;
    RenderTexture rt = RenderTexture.GetTemporary(newWidth, newHeight);
    rt.filterMode = FilterMode.Point;
    RenderTexture.active = rt;
    Graphics.Blit(source, rt);
    var nTex = new Texture2D(newWidth, newHeight);
    nTex.ReadPixels(new Rect(0, 0, newWidth, newHeight), 0, 0);
    nTex.Apply();
    RenderTexture.active = null;
    return nTex;
}

posted on 2019-08-18 21:04  伊景轩  阅读(1295)  评论(0编辑  收藏  举报

导航