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
はい、このコードサンプルに基づいて推測することはできますが、両方の呼び出しで同じファイル名を再利用している可能性があります。 – BlakeH
ファイル名は異なりますが、例外はありません。結果は1つのファイルがプログラムの最後に保存されている –