Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How can i calculate the memory size of an image enclosed in a picture box?
Posted
Updated 30-Nov-11 4:46am
v4

If you know the location of the image then you can do the following:

FileInfo imageInfo = new FileInfo(imagePath);

int sizeInBytes = imageInfo.Length;


if you are creating the image yourself and you know the width and height in pixels aswell as the colour depth then you can use the following formula to work out the size of the image in kilobytes.

Division by 8 will give you an answer in bytes
Division by 8*1024 will give you an answer in Kb
Division by 8*1024*1024 will give you an answer in Mb

CSS
            width in pixels × height in pixels × colour depth
SizeInKb = ___________________________________________________

                        8 × 1024



The following is a table of colour depth

Colour Depth in Bits    Number of Colours   Number of Colours calculations

1                         2                   2^1 = 2
 
2                         4                   2^2 = 4 

3                         8                   2^3 = 8 

4                         16                  2^4 = 16

5                         32                  2^5 = 32

6                         64                  2^6 = 64

7                         128                 2^7 = 128

8                         256                 2^8 = 256

16                        65536               2^16 = 65563

24                        16777216            2^24 = 16777216  

32                        4294967296          2^32 = 4294967296


etc
 
Share this answer
 
v6
Convert image to Array of bytes. Then get the size in byte and calculate it in Kb or Mb.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900