使用Emgu CV将图像保存到文件夹中

问题描述 投票:0回答:1

我有一些图像是使用Emgu CV从其他图像中提取的。

我尝试将这些图像保存到文件夹中,但是只有最后一张图像和我的代码一起保存到了文件夹中。

 Image.ToBitmap().save("filename",imageformat.png)

如何将所有图像保存在一个文件夹中?

c# emgucv
1个回答
0
投票

您可以尝试执行类似的操作。我已经取了文件的名称,然后询问文件是否已经存在,如果存在,它会在文件名中添加数字,并且这样做会保持文件格式。但是,如果您不想使用文件格式保存它,则只需添加文件名fileName.Split();后面的数字,就可以不用newFileName = fileName+$"_{i}";来保存它。 如果这有助于将其标记为答案。

//if you want you can use this method or just copy the code you need
void Unique(Image input)
{
    string fileName = "filename.jpg";
    string newFilename = null;
    for(int i = 1; true; i++)

        //this is so that you can alter the name and keep the file format 
        newFileName = filename.Split('.')[0]+"_{i}"+filename.Split('.')[1];

        if(!File.Exist(newFileName))
        {   
            break;
        }
    }
    Image.ToBitmap().Save(newFileName,ImageFormat.Png);
}
© www.soinside.com 2019 - 2024. All rights reserved.