我有这段代码,如何让它接受所有典型的图像格式? PNG、JPEG、JPG、GIF?
这是我目前所拥有的:
public void EncryptFile()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.InitialDirectory = @"C:\";
dialog.Title = "Please select an image file to encrypt.";
if (dialog.ShowDialog() == DialogResult.OK)
{
//Encrypt the selected file. I'll do this later. :)
}
}
请注意过滤器设置为 .txt 文件。我可以更改为 PNG,但其他类型呢?
最佳答案
来自 the docs ,您需要的过滤器语法如下:
Office Files|*.doc;*.xls;*.ppt
即用分号分隔多个扩展名——因此,Image Files|*.jpg;*.jpeg;*.png;...
。
关于c# - 将过滤器设置为 OpenFileDialog 以允许典型的图像格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2069048/