Compact Framework 2: Image.Save() produces bmp files with corrupt header! - by NullReference

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 214834 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/29/2006 2:28:12 AM
Duplicates 214835 Access Restriction Public

Description

I tried to save a picturebox's image to a bitmap file. This file then could be read by some applications, but some told me that the bitmap file is not "valid".

I then looked into the bmp file header and noticed that the height is wrong. 
It reads CE FF FF FF instead of 32 00 00 00 (50).

I used this code on a 50x50 picturebox image:
pictureBox1.Image.Save(@"\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Sign in to post a comment.
Posted by Morales R on 8/14/2009 at 9:19 PM
An old book , but take a look.. !! Im so frustrated everytime there is some point that requires more work..

http://books.google.com/books?id=_nJLvY757dQC&lpg=PA25&ots=0dVJ-4dl7l&dq=bmp%20file%20negative%20header%20image%20height&pg=PA25#v=onepage&q=bmp%20file%20negative%20header%20image%20height&f=false
Posted by NullReference on 1/17/2007 at 10:45 PM
OK, You're right. My docs did not contain this information.

Nevertheless this behaviour is causing us problems. It seems there is more software out there which used the same docs. So its questionable why the CF team chose the top-down format and|or did not create a parameter for this. We still have to work around this.

Thanks for your help.
Posted by Microsoft on 1/17/2007 at 1:47 PM
the biHeight field in the BITMAPINFOHEADER struct allows for either positive or negative values (http://msdn2.microsoft.com/en-gb/library/aa452885.aspx). Bitmaps can be stored either top down or bottom up and the sign of the biHeight field is used to indicate this.
Posted by NullReference on 1/17/2007 at 4:41 AM
But the bitmap is not top-down.
Posted by Microsoft on 1/16/2007 at 3:13 PM
A negative height value is valid in the header of a bitmap. It indicates that the bitmap is top-down and non-compressed.