• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Read BITMAPINFOHEADER and get width and height of the image

Hello

i wrote some code :

            FileStream fs = File.OpenRead(@"c:\Zapotec.bmp");
            BinaryReader breader = new BinaryReader(fs);
            breader.BaseStream.Seek(16,SeekOrigin.Begin);
            Int32 width = breader.ReadInt32();
            Int32 height = breader.ReadInt32();
            breader.BaseStream.Seek(2,SeekOrigin.Current);
            Int16 biBitCount = breader.ReadInt16();
           

            fs.Close();
            breader.Close();

but i am getting very large number in width  and in height
please help me to get the right size.
becouse if i am loading this image for example:
Bitmap bmp = new Bitmap(@"c:\Zapotec.bmp");
bmp.width  and bmp.height  much smoller.

please help me
i need only this 2 parameters and we are working with very big images so we can't load image we need only to get this 2 parameters.

thx

0
dcave555
Asked:
dcave555
1 Solution
 
OfficeLinemanCommented:
Suggest setting your first seek to 18, instead of 16.
0
 
Bob LearnedCommented:
Is there a reason that you are doing it that way, instead of this way:

Bitmap bmp = new Bitmap(@"c:\windows\zapotec.bmp");
int height = bmp.Height;
int width = bmp.Width;

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now