Can there be a better way than this?

//Преобразование изображения в строку public string ImgToStr(string filename) { MemoryStream Memostr = new MemoryStream(); Image Img = Image.FromFile(filename); Img.Save(Memostr, Img.RawFormat); byte[] arrayimg = Memostr.ToArray(); return Convert.ToBase64String(arrayimg); } //Преобразование строки в изображение public Image StrToImg(string StrImg) { byte[] arrayimg = Convert.FromBase64String(StrImg); Image imageStr = Image.FromStream(new MemoryStream(arrayimg)); return imageStr; } 
  • one
    Why do you need it at all? The line will be unreadable. Why not just use byte[] ? - Andrei NOP
  • one
    Why is it so difficult, through the stream and opening it as an image? okay would be checking the existence of a file public string fileToBase64(string filename) { byte[] fileBytes = File.ReadAllBytes(filename); return Convert.ToBase64String(fileBytes); } public string fileToBase64(string filename) { byte[] fileBytes = File.ReadAllBytes(filename); return Convert.ToBase64String(fileBytes); } - Alias
  • In fact, this is just for development, in the application, pictures are selected via OpenDialog, and then I haven't thought of it yet) - Alias ​​Tray
  • Can cram into the database))) - Alias ​​Tray

0