如何在运行时获取原生图像大小?

时间:2015-06-08 12:36:59

标签: c#

我需要使用图像的高度和宽度来缩放平面,因此平面的主要纹理不会拉伸。 像这样:

    void LoadBG()
{
    string bgpaht = Application.persistentDataPath +"/a.png";
    if (File.Exists(bgpath))
    {
        byte[] bgbyte=File.ReadAllBytes(bgpath);
        ...
        ...
        Texture2D t2d = new Texture2D(a.width,a.height); 
        t2d.LoadImage(bgbyte);
        plane.transform.localScale = new Vector3(t2d.width,1.0f,t2d.height);
        plane.renderer.material.mainTexture=t2d;

    }
}

好的,现在我怎样才能得到图像的宽度和高度" a.png"?

1 个答案:

答案 0 :(得分:0)

你看过Image班了吗?

https://msdn.microsoft.com/en-us/library/System.Drawing.Image(v=vs.110).aspx

它具有属性HeightWidth

只需像这样加载图片

Image yourImage = Image.FromFile(pathOfYourFile);
相关问题