Read BITMAPINFOHEADER and get width and height of the image

Posted on 2006-04-25
Last Modified: 2008-01-09

i wrote some code :

            FileStream fs = File.OpenRead(@"c:\Zapotec.bmp");
            BinaryReader breader = new BinaryReader(fs);
            Int32 width = breader.ReadInt32();
            Int32 height = breader.ReadInt32();
            Int16 biBitCount = breader.ReadInt16();


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.


Question by:dcave555
    LVL 2

    Accepted Solution

    Suggest setting your first seek to 18, instead of 16.
    LVL 96

    Expert Comment

    by:Bob Learned
    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;


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now