-2

I am facing a problem and i really cant get out of it, i tried to search for some solutions but ran out of all ideas.. So i am selecting a number of files all names are numbers example 1.png , 2.png 3.png etc etc What i want is that when loading 2.png i get the filename for example 2 ( excluding the extension) check for a condition for example and if else condition and store the output in another list. Is it possible ? The code below shows how im loading a file and another thing which i am doing ( basically getting the image and passign the image to another method.

OpenFileDialog x = new OpenFileDialog();
        x.FileName = "";
        x.Multiselect = true;
        x.ShowDialog();
        x.Title = "Images";
        x.Filter = "Files|*.png";

        string[] result = x.FileNames;

        if (openFileDialog1.FileNames.ToString() != "")
        {
            foreach (string y in result)
            {

                img = new Bitmap(y);
                ContoBin(img);     
            }                


        }
4

1 回答 1

0

您是否要在没有扩展名的情况下获取文件名?

foreach (string y in result)
{
    if((Path.GetFileNameWithoutExtension(y) == "2")
    {
         // do stuff with 2.png
    }  

    ...

确保你有

using System.IO;

在代码文件的顶部

于 2012-11-28T22:09:04.827 回答