如果图像打开...其他打开?

时间:2013-04-20 21:55:52

标签: c# wpf windows image

我只是想知道是否有人知道如何编写代码如何检查项目是否为图像然后打开Windows图像预览其他打开使用内置媒体播放器。

代码是这样的:

private bool listbox3job()
{
    AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
    WMPLib.IWMPPlaylist playlist = axWmp.newPlaylist("myPlaylist", string.Empty);
    DateTime? start = starttid2.Value;
    DateTime? end = sluttid2.Value;
    DateTime now = DateTime.Now;

    if (start == null || end == null)
    {
        return false;
    }
    else if (now >= start.Value && now <= end.Value)
    {
        foreach (var selected in listBox3.Items)
        {
            string s = selected.ToString();
            if (listBox3Dict.ContainsKey(s))
            {
    if (extentions.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
    {
        Process process = new Process();
        process.StartInfo.FileName = "rundll32.exe";
        process.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " + listBox3Dict[s];
        process.Start();
        Thread.Sleep(7000);
        {
            exit();
        }
    }
    else
    {
                WMPLib.IWMPMedia temp = axWmp.newMedia(listBox3Dict[s]);  
                playlist.appendItem(temp);
                axWmp.settings.setMode("loop", true);
                axWmp.settings.autoStart = true;
                axWmp.currentPlaylist = playlist; 
    }
            }
        }
                return true;
    }
    return false;
}

1 个答案:

答案 0 :(得分:1)

你在这里

 public static List<string> extentions = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" };

private void Open()
{

    foreach (var selected in listBox4.Items)
    {
        string s = selected.ToString();

        if (listBox4Dict.ContainsKey(s))
        {
            if (extentions.Contains(Path.GetExtension(s).ToUpperInvariant()))
            {
                Process process = new Process();
                process.StartInfo.FileName = "rundll32.exe";
                process.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " +listBox4Dict[s];
                process.Start();
                process.WaitForExit();
                while (!process.HasExited)
                    Thread.Sleep(500);
            }
            else
            {
                Mediaplayer.URL = (listBox4Dict[s]);
            }
        }
    }
}