Beispiel #1
0
        public MainWindow(string fileName)
        {
            InitializeComponent();

            //  fileName ="E:\\Repos\\piview\\vs-project\\testimg\\test-ppm1.ppm";      // test

            if (!File.Exists(fileName))
            {
                return;
            }

            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            fileStream.Seek(0, SeekOrigin.Begin);

            ImageSource imgSource = ImageFileUtils.LoadPPM(out m_imgWidth, out m_imgHeight, fileStream);

            if (null == imgSource)
            {
                MessageBox.Show("Cannot decode this format's image file.", "Error!");
            }
            fileStream.Close();

            imgShow.Source = imgSource;

            string imgRepoPath = fileName.Substring(0, fileName.LastIndexOf('\\'));

            imgRepoPath += '\\';
            m_imgList    = ScanImageFiles(imgRepoPath);
            m_imgSeq     = m_imgList.IndexOf(fileName);

            m_showable = true;
            Title      = "piview - " + fileName;
        }
Beispiel #2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.Key)
            {
            case Key.Right:
                if (m_imgList.Count == 0 || m_imgList.Count == 1)
                {
                    return;
                }

                if (m_imgSeq == m_imgList.Count - 1)
                {
                    m_imgSeq = 0;
                }
                else
                {
                    ++m_imgSeq;
                }

                using (FileStream fileStream = new FileStream(m_imgList[m_imgSeq], FileMode.Open, FileAccess.Read))
                {
                    fileStream.Seek(0, SeekOrigin.Begin);
                    ImageSource imgSource = ImageFileUtils.LoadPPM(out m_imgWidth, out m_imgHeight, fileStream);
                    if (null == imgSource)
                    {
                        MessageBox.Show("Cannot decode this format's image file.", "Error!");
                    }
                    fileStream.Close();

                    imgShow.Source = imgSource;
                    Title          = "piview - " + m_imgList[m_imgSeq];
                }
                break;

            case Key.Left:
                if (m_imgList.Count == 0 || m_imgList.Count == 1)
                {
                    return;
                }

                if (m_imgSeq == 0)
                {
                    m_imgSeq = m_imgList.Count - 1;
                }
                else
                {
                    --m_imgSeq;
                }

                using (FileStream fileStream = new FileStream(m_imgList[m_imgSeq], FileMode.Open, FileAccess.Read))
                {
                    fileStream.Seek(0, SeekOrigin.Begin);
                    ImageSource imgSource = ImageFileUtils.LoadPPM(out m_imgWidth, out m_imgHeight, fileStream);
                    if (null == imgSource)
                    {
                        MessageBox.Show("Cannot decode this format's image file.", "Error!");
                    }
                    fileStream.Close();

                    imgShow.Source = imgSource;
                    Title          = "piview - " + m_imgList[m_imgSeq];
                }

                break;

            default:
                break;
            }
        }