I am currently writing a system that stores meta data for around 140,000 ish images stored within a legacy image library that are being moved to cloud storage. I am using th
If you get your image directly from file, you can use the following code to get size of original file in bytes.
var fileLength = new FileInfo(filePath).Length;
If you get your image from other source, like getting one bitmap and composing it with other image, like adding watermark you will have to calculate size in run-time. You can't just use original file size, because compressing may lead to different size of output data after modification. In this case, you can use MemoryStream to save image to:
long jpegByteSize;
using (var ms = new MemoryStream(estimatedLength)) // estimatedLength can be original fileLength
{
image.Save(ms, ImageFormat.Jpeg); // save image to stream in Jpeg format
jpegByteSize = ms.Length;
}
System.Drawing.Image
won't give you the file length of size. You have to use another library for that.
int len = (new System.IO.FileInfo(sFullPath)).Length;
If you don't have the original file, the file size is not clear as it depends on the image format and quality. So what you'd have to do is write the image to a stream (e.g. MemoryStream) and then use the stream's size.