In C#
Conversion from picture to byte[] and then to base64string:
Bitmap bmp = new Bitmap(filepath); MemoryStream ms = new MemoryStream(); (ms, ); byte[] arr = new byte[]; = 0; (arr, 0, (int)); (); string pic = Convert.ToBase64String(arr);
base64string to byte[] and then to image conversion:
byte[] imageBytes = Convert.FromBase64String(pic); //Read in MemoryStream objectMemoryStream memoryStream = new MemoryStream(imageBytes, 0, ); (imageBytes, 0, ); //Convert to pictureImage image = (memoryStream);
In the current database development, the storage method of images is generally CLOB: storage base64string
BLOB: Store byte[]
It is generally recommended to use byte[]. Because the image can be directly converted to byte[] and stored in the database
If you use base64string, you also need to convert from byte[] to base64string. More waste of performance.
The above conversion method of the picture.BYTE[] and base64string in C# is all the content I share with you. I hope you can give you a reference and I hope you can support me more.