Open image in Windows Photo Viewer

前端 未结 3 1495
萌比男神i
萌比男神i 2020-12-05 23:09

How to open .jpg image in Windows Photo Viewer from C# app?

Not inside app like this code,

FileStream stream = new FileStream(\"test.p         


        
相关标签:
3条回答
  • 2020-12-05 23:48

    The code fetch photo from ftp and shows the photo in Windows Photo Viewer. I hope it will usefully for you.

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

    Best Regards...

    0 讨论(0)
  • 2020-12-05 23:49

    I think you can just use:

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

    And this will use the standard file viewer associated with .jpg files - by default the windows picture viewer.

    0 讨论(0)
  • 2020-12-06 00:13

    Start it in a new Process

    Process photoViewer = new Process();
    photoViewer.StartInfo.FileName = @"The photo viewer file path";
    photoViewer.StartInfo.Arguments = @"Your image file path";
    photoViewer.Start();
    
    0 讨论(0)
提交回复
热议问题