我试图用File.WriteAllBytes()保存多个图像,即使在我试图单独保存与'Thread.Sleep()'它不工作..使用File.WriteAllBytes保存多个图像只保存最后一个
我的代码:
byte[] signatureBytes = Convert.FromBase64String(model.Signature);
byte[] idBytes = Convert.FromBase64String(model.IdCapture);
//Saving the images as PNG extension.
FileManager.SaveFile(signatureBytes, dirName, directoryPath, signatureFileName);
FileManager.SaveFile(idBytes, dirName, directoryPath, captureFileName);
SAVEFILE功能:
public static void SaveFile(byte[] imageBytes, string dirName, string path, string fileName, string fileExt = "jpg")
{
if (!string.IsNullOrEmpty(dirName)
&& !string.IsNullOrEmpty(path)
&& !string.IsNullOrEmpty(fileName)
&& imageBytes.Length > 0)
{
var dirPath = Path.Combine(path, dirName);
var di = new DirectoryInfo(dirPath);
if (!di.Exists)
di.Create();
if (di.Exists)
{
File.WriteAllBytes(dirPath + [email protected]"\{fileName}.{fileExt}", imageBytes);
}
}
else
throw new Exception("File cannot be created, one of the parameters are null or empty.");
}
*不工作*是什么意思?你是否遇到异常? – MarcinJuraszek
Yea只能基于此代码示例进行猜测,但也许您正在重复使用两个调用的相同文件名 – BlakeH
这些文件的名称是不同的,没有例外。只有在程序结束时保存1个文件的结果 –