I search to get the file size (in bytes) of an image in C# :
I get the image in a base64 string, but in this format I have the impression it's no possible to get the file size.
So I transforme it in an image object like this :
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(imageSrc);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image imageObj = Image.FromStream(ms, true);
But i'm not able to get the file size. I can have the dimensions or the type but not the file size.
Have you got an idea on that please?
You already have the size of your image in bytes, you can get it like this:
imageBytes.Length
As I understood, you don't want to convert it to another format, just save it, so you can save your bytes directly to your file, the simplest solution:
File.WriteAllBytes(string yourpath, byte[] yourbytes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With