Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从图像类类型获取图像文件路径_C#_Windows_Image - Fatal编程技术网

C# 从图像类类型获取图像文件路径

C# 从图像类类型获取图像文件路径,c#,windows,image,C#,Windows,Image,我有一个关于C#图像类类型的查询。考虑下面的语句 Image img = Image.LoadFromFile(@"C:\1.jpg"); 问题:如何从img变量获取图像文件路径 猜测: 我不认为我们可以有图像路径,因为如果我们看到LoadFromFile方法,它会从物理文件路径读取图像,并将其逐字节加载到内存中。一旦它被加载,它将在img对象中。img对象现在将独立于磁盘上的映像物理文件 尝试使用以下方法 img.ImageUrl 您的猜测是正确的,图像对象在加载到内存后没有与文件的连接

我有一个关于
C#
图像类类型的查询。考虑下面的语句

Image img = Image.LoadFromFile(@"C:\1.jpg");
问题:如何从
img
变量获取图像文件路径

猜测:
我不认为我们可以有图像路径,因为如果我们看到LoadFromFile方法,它会从物理文件路径读取图像,并将其逐字节加载到内存中。一旦它被加载,它将在img对象中。img对象现在将独立于磁盘上的映像物理文件

尝试使用以下方法

 img.ImageUrl

您的猜测是正确的,图像对象在加载到内存后没有与文件的连接。您需要将路径存储在单独的变量中,或者执行以下操作:

public class ImageEx
{
    public Image Image { get; set; }
    public string Filename { get; set; }

    public ImageEx(string filename)
    {
        this.Image = Image.FromFile(filename);
        this.Filename = filename;
    }
}

public class SomeClass
{
    public void SomeMethod()
    {
        ImageEx img = new ImageEx(@"C:\1.jpg");

        Debug.WriteLine("Loaded file: {0}", img.Filename);
        Debug.WriteLine("Dimensions: {0}x{1}", img.Image.Width, img.Image.Height);
    }
}

我找不到那处房产。我正在使用Windows C#system.drawing.Image类