c# 調用系統默認圖片瀏覽器打開圖片


private void OpenImage(string fileName)
        {
            try
            {
                Process.Start(fileName);
            }
            catch (Exception ex)
            {
               // LogHelper.WriteLog("調用默認看圖軟件打開失敗", ex);
                try
                {
                    string arg =
                        string.Format(
                            "\"{0}\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen  {1} ",
                            Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
                            , fileName);
                    var dllExe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),
                        "rundll32.exe");
                   // LogHelper.WriteLog(string.Format("調用系統默認的圖片查看器打開圖片,參數為:{0} {1}", dllExe, arg));
                    System.Diagnostics.Process.Start(dllExe, arg);
                }
                catch (Exception e)
                {
                   // LogHelper.WriteLog("系統圖片查看器打開圖片失敗", ex);
                   
                    //打開文件夾並選中文件
                    var argment = string.Format(@"/select,""{0}""", fileName);
                    System.Diagnostics.Process.Start("Explorer", argment);
                }
            }
        }
View Code

說明,這個代碼適用於程序的目標平台為x86

如果是x64,那么就需要做適當修改


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM