开发者

Open image in Windows Photo Viewer

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

Not inside app like this code, 开发者_Go百科

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


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.


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


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...


public void ImageViewer(string path)
        {            
            Process.Start("explorer.exe",path);            
        }

Path is the file path of the image to be previewed.


I am trying the other answers but they all return the same error about how the location isn't an OS App, so I'm not sure where the issue lies. I did however discover another method to open the file.

string Location_ToOpen = @"The full path to the file including the file name";
if (!File.Exists(Location_ToOpen))
{
   return;
}

string argument = "/open, \"" + Location_ToOpen + "\"";

System.Diagnostics.Process.Start("explorer.exe", argument);

It starts out by testing if the file exists or not. If it doesn't exist it would have caused an error.

After that it simulates a "open" request on a file explorer without opening a file explorer, then the system opens the file with the default app.

I am currently using this method in my project so I hope it works for you too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜