c# - How windows calculate file dimension? -


i calculate binary size of file function:

 public static int binarysize(string path)         {             filestream fs = new filestream(path, filemode.open);             int hexin;             string ret = "";             (int = 0; (hexin = fs.readbyte()) != -1; i++)             {                 ret += convert.tostring(hexin, 2);              }             fs.close();             return ret.length;         }  

an example of problem when calculate dimension of simple black png image (10x10 pixels) myimage

with function find 640 bits => 80 bytes, windows file dimension 136 byte. why difference of 56 bytes? security, permissions or private information windows attach every file?

convert.tostring(hexin,2) not return 8 characters, trims leading zeroes, if hexin 4, returns 100, not 00000100.

you might want change convert.tostring(hexin,2).padleft(8, '0');. you'd want use stringbuilder instead of string ret variable.

by way, reading file determine size bit wasteful. better use fileinfo class file information.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -