如何使用openfiledialog拍摄图像而不是将一个图像放入程序中 [英] How to using openfiledialog to take image rather than put one image in program

查看:59
本文介绍了如何使用openfiledialog拍摄图像而不是将一个图像放入程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string pathToImage = @"test1.gif";
pathToImage = AppDomain.CurrentDomain.BaseDirectory + pathToImage;

 //Try extracting the frames
 frames = EnumerateFrames(pathToImage);
 if (frames == null || frames.Count() == 0) {
     MessageBox.Show("Unable to obtain frames from " + pathToImage);
 }

 for (int i = 0; i < frames.Count(); i++)
 {
     ListBox1.Items.Add("Frame-" + i.ToString());
 }







我的尝试:






What I have tried:

OpenFileDialog dlg = new OpenFileDialog();

                dlg.Title = "Open Image";
                dlg.Filter = "GIF files (*.gif)|*.gif";
                dlg.ShowDialog();

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string pathToImage = dlg.FileName;

                }

                
                frames = EnumerateFrames(pathToImage);
                if (frames == null || frames.Count() == 0)
                {
                    MessageBox.Show("Unable to obtain frames from " + pathToImage);
                }

                for (int i = 0; i < frames.Count(); i++)
                {
                    ListBox1.Items.Add("Frame-" + i.ToString());
                }

推荐答案

您有两次调用ShowDialog,删除第一个:

You have two calls to ShowDialog, delete the first one:
string pathToImage;
dlg.Title = "Open Image";
dlg.Filter = "GIF files (*.gif)|*.gif";

if (dlg.ShowDialog() == DialogResult.OK)
{
    pathToImage = dlg.FileName;

}


这篇关于如何使用openfiledialog拍摄图像而不是将一个图像放入程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆