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 |
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:
a)
Bitmap bm = new Bitmap(100,100);
bm.Save("picture.jpg", ImageFormat.Jpeg);
- and -
b)
Bitmap bm = new Bitmap(100,100);
bm.Save("picture.jpg");
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); bm.Save("test.jpg"); bm.Save("test.png");
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.