Bitmap file size compared to byte []

bmp.ToByteArray(ImageFormat.Bmp).Length 3145782 int but the file system is displayed as 2,25 MB (2.359.350 bytes) and Size on disk 2,25 MB (2.363.392 bytes)

Why is there a difference and how can I determine the correct size of the bitmap in the byte [] form?

    string appPath = Application.StartupPath;

    var bmp = new Bitmap(Image.FromFile(appPath + "\\Images\\Penguins.bmp"));

    public static byte[] ToByteArray(this Image image, ImageFormat format)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            image.Save(ms, format);
            return ms.ToArray();
        }
    }

Windows 7 / NTFS

+4
source share
1 answer

I suspect that since the file on disk does not contain an alpha channel, but in memory it does. On disk, it's 3 bytes per pixel, but in memory it uses 4.

2359350 * 4/3 - 3145800, which is slightly larger than the value you see. I expect the slight difference is that there is a title on the disc, but this is actually not part of the image.

+2
source

All Articles