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

Bel*_*szz 21 c# image winforms

如何.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)

ian*_*lly 82

我想你可以使用:

Process.Start(@"C:\MyPicture.jpg");
Run Code Online (Sandbox Code Playgroud)

这将使用与.jpg文件关联的标准文件查看器 - 默认情况下是Windows图片查看器.

  • 不适合我。`指定的可执行文件不是此操作系统平台的有效应用程序` (7认同)
  • 使用Process.Start()的最好的部分是它不关心你给它的文件类型,它只使用默认的查看器.即PDF将在Adobe Viewer中自动打开. (4认同)

Jal*_*aid 16

在新流程中启动它

Process photoViewer = new Process();
photoViewer.StartInfo.FileName = @"The photo viewer file path";
photoViewer.StartInfo.Arguments = @"Your image file path";
photoViewer.Start();
Run Code Online (Sandbox Code Playgroud)

  • 每个人都知道,但是Windows中默认的图像查看器的名称是什么? (2认同)

小智 7

public void ImageViewer(string path)
        {            
            Process.Start("explorer.exe",path);            
        }
Run Code Online (Sandbox Code Playgroud)

Path是要预览的图像的文件路径。


小智 5

该代码从 ftp 获取照片并在 Windows 照片查看器中显示照片。我希望它对你有用。

  public void ShowPhoto(String uri, String username, String password)
        {
            WebClient ftpClient = new WebClient();
            ftpClient.Credentials = new NetworkCredential(username,password);
            byte[] imageByte = ftpClient.DownloadData(uri);


            var tempFileName = Path.GetTempFileName();
            System.IO.File.WriteAllBytes(tempFileName, imageByte);

            string path = Environment.GetFolderPath(
                Environment.SpecialFolder.ProgramFiles);

            // create our startup process and argument
            var psi = new ProcessStartInfo(
                "rundll32.exe",
                String.Format(
                    "\"{0}{1}\", ImageView_Fullscreen {2}",
                    Environment.Is64BitOperatingSystem ?
                        path.Replace(" (x86)", "") :
                        path
                        ,
                    @"\Windows Photo Viewer\PhotoViewer.dll",
                    tempFileName)
                );

            psi.UseShellExecute = false;

            var viewer = Process.Start(psi);
            // cleanup when done...
            viewer.EnableRaisingEvents = true;
            viewer.Exited += (o, args) =>
            {
                File.Delete(tempFileName);
            };


        }
Run Code Online (Sandbox Code Playgroud)

此致...