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

时间:2011-07-24 16:20:23

标签: c# winforms image

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

不在此代码内的应用内,

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

3 个答案:

答案 0 :(得分:81)

我认为你可以使用:

Process.Start(@"C:\MyPicture.jpg");

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

答案 1 :(得分:16)

以新的Process

开头
Process photoViewer = new Process();
photoViewer.StartInfo.FileName = @"The photo viewer file path";
photoViewer.StartInfo.Arguments = @"Your image file path";
photoViewer.Start();

答案 2 :(得分:1)

该代码从ftp获取照片,并在Windows Photo Viewer中显示该照片。 希望对您有用。

  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);
            };


        }

最好的问候...