自定义筛选打开文件对话框



我正在尝试制作一个允许用户查看PictureBox中的图标的程序。我希望用户只能打开 24x24 像素的图像。

我想在OpenFileDialog中放置一个过滤器,以仅显示24x24的图像。有什么办法可以做到这一点吗?我听说可以通过自定义OpenFileDialog并使用P/Invoke来实现。

您可以检查图像的WidthHeight

// 'image' is the image you want to check
if(image.Width > 24 || image.Height > 24)
    MessageBox.Show("Please select a smaller image!");
else
    // This code will always run if the image is smaller than 24x24

希望这有帮助!

如果你通过将其存储为对象来读取它(我假设你是),你只需要读取imageObject.Width"using System.Drawing;"或"using System.Drawing.Image;"

这里和这里的例子。

你不能用OpenFileDialog来做到这一点。 您需要编写自己的对话框,用于询问每个文件夹中的文件并确定它们是否符合您的条件,然后仅显示这些文件。

最新更新