image を base64 文字列に、base64 文字列を image に変換できます。そして、画像を特定の場所に保存しています。初めて実行すると、入力として指定した正しい画像ファイルが取得されます。しかし、2回目の実行から、私が渡す入力画像が何であれ、最初の入力画像しか得られません。
望ましい出力: 渡した入力画像を取得する必要があります。
変換コード:
public string ImageToBase64(Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
保存ファイル コード:
public void retreiveAndSaveImgFile(string base64formofstr)
{
Console.WriteLine("the incoming string :: " + base64formofstr.Length);
/* Bitmap bitmap = new Bitmap(Base64ToImage(base64formofstr));
Bitmap newBitmap = new Bitmap(bitmap);
newBitmap.SetResolution(150, 150); // resolution of the original image for which the zone template is created
newBitmap.Save("D:\\Suraya\\TesttogetCorrectPutput\\MICR_SAMPLE.tif", ImageFormat.Tiff);*/
Base64ToImage(base64formofstr).Save("D:\\Suraya\\TesttogetCorrectPutput\\MICR_SAMPLE.tif");
}
この問題を解決するために私を助けてください。