首页 > Windows开发 > 详细

c# 调用系统默认图片浏览器打开图片

时间:2019-01-31 11:22:07      阅读:418      评论:0      收藏:0      [点我收藏+]
技术分享图片
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,那么就需要做适当修改

c# 调用系统默认图片浏览器打开图片

原文:https://www.cnblogs.com/sczmzx/p/10340866.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!