相关疑难解决方法(0)

在Windows照片查看器中打开图像

如何.jpg从C#app在Windows Photo Viewer中打开图像?

不像这段代码那样在app里面,

FileStream stream = new FileStream("test.png", FileMode.Open, FileAccess.Read);
pictureBox1.Image = Image.FromStream(stream);
stream.Close();
Run Code Online (Sandbox Code Playgroud)

c# image winforms

21
推荐指数
4
解决办法
4万
查看次数

应用程序是否与给定的扩展相关联?

有时需要让您的应用程序打开文件的默认应用程序.例如,要打开PDF文件,您可以使用:

System.Diagnostics.Process.Start("Filename.pdf");
Run Code Online (Sandbox Code Playgroud)


要打开图像,您只需使用具有不同文件名的相同代码:

System.Diagnostics.Process.Start("Filename.gif");
Run Code Online (Sandbox Code Playgroud)


一些扩展(例如.gif)几乎总是有一个默认的处理程序,即使在基本的Windows安装中也是如此.但是,某些扩展(例如.pdf)通常没有安装应用程序来处理它们.

在这些情况下,在调用Process.Start(fileName)之前,最好确定应用程序是否与要打开的文件的扩展名相关联.

我想知道如何最好地实现这样的事情:

static bool ApplicationAssociated(string extension)
{
    var extensionHasAssociatedApplication = false;

    var condition = // Determine if there is an application installed that is associated with the provided file extension.;
    if (condition)
    {
        extensionHasAssociatedApplication = true;
    }

    return extensionHasAssociatedApplication;
}
Run Code Online (Sandbox Code Playgroud)

c# file-extension

13
推荐指数
3
解决办法
9308
查看次数

标签 统计

c# ×2

file-extension ×1

image ×1

winforms ×1