Conrad Blog:

January 2014
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

April 2009
March 2009
February 2009
January 2009
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
October 2006
August 2006
July 2006
June 2006
May 2006
April 2006
February 2006
January 2006
December 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
Recent Entries
The Cube
Some pics
Introducing the "I Heart Heart Cat Cat Map Map App App"
Art Inspiration
Twitter is down...
On Editing Drum Flams
Song-A-Nowandthen: Nervous Machine
Naughty Rams, Caught on Video!
Building the A12 Microphone Preamp
Faulty .NET Certification Materials - Image.Save()
Cool stuff you should see:
TapeOp Board
Syndicate this site (XML)
Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35

September 2, 2008

Faulty .NET Certification Materials - Image.Save()

After taking a MCTS certification practice test and getting several questions wrong, I started delving into them to figure out what I needed to study. It was then that I found a question asking how to save an image as a JPEG. The test claims that there are two correct answers:


Bitmap bm = new Bitmap(100,100);
bm.Save("picture.jpg", ImageFormat.Jpeg);

- and -


Bitmap bm = new Bitmap(100,100);

The only difference between the two is the parameters used in the call to Bitmap.Save(). I didn't check the last option, because I wasn't sure what in which format the image would be saved. The test explanation says that "If you don't specify an image format, Bitmap.Save defaults to the JPEG format." Hmm, really?

I had found some dissenting opinions on the net, and the MSDN documentation clearly states that "If no encoder exists for the file format of the image, the Portable Network Graphics (PNG) encoder is used."

Of course, there's nothing like actually trying the thing out and seeing what it REALLY does. So built a console app that simply does the following:

Bitmap bm = new Bitmap(100, 100);

Both files loaded fine in Windows Picture & Fax Viewer, but trying to load the "jpeg" file in Photoshop proves the png theory with the message "Could not complete your request because a JPEG marker segment length is too short (the file may be truncated or incomplete)." Or it may be because IT'S NOT A JPEG, guys. I thought I would post a clarification on the web, since I didn't see anything when I did a Google search. Hopefully it will help out other poor confused souls, as well.

This error is from the official Microsoft Press study guide. Let's hope the actual test doesn't contain these sorts of inaccuracies... I've got a $125 test fee riding on it.

Posted by pedalboy at September 2, 2008 4:16 PM | TrackBack

I always assumed that it saved as a Bitmap when no ImageFormat was specified; but I know for certain it doesn't save as a jpg. You can smell a jpg saved with "bm.Save("picture.jpg", ImageFormat.Jpeg);" a mile away because of the resulting default low-quality.

Good luck on the test!

Posted by: Jaron Davis at September 3, 2008 11:59 AM
Post a comment

Remember personal info?