我試圖用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個文件的結果 –