The PixelFormat
enumeration is concerned with how many bits each pixel takes up when the image data is in uncompressed bitmap form (e.g. in-memory on your computer when you load an image file). File formats like JPEG and PNG do not have a comparable concept of bits-per-pixel because they're compressed formats that don't necessarily store each pixel in 24 bits of space on-disk.
As an aside, JPEG always uses 24 bits to store colour information (to the extent it does store colour, JPEG's algorithm is quite complicated actually), and PNG supports at least indexed colour, 24-bit RGB and 32-bit ARGB colour depth. PNG also supports 48-bit colour depth too.
Back on-topic: you're seeing increased JPEG file sizes because JPEG is a lossy algorithm that has the side-effect of introducing compression artefacts. While saving an original photo to a highly compressed JPEG image causes information loss, these artefacts actually add (unwanted) new details to the image, so when re-saving these new artefacts you're increasing the amount of "information" that needs to be stored, hence why the file-size increases. This will also cause the image to progressively lose quality each time it's re-saved - as compressed-bits that should be used to represent the original image are now being wasted to represent the artefacts that were introduced by a previous re-encoding of the JPEG image.
(There are ways to losslessly re-save JPEG images without running JPEG's algorithm again, but most image editors nor GDI support them, search for "jpegtrans" and "jpegcrop" for more information).
If you want to reduce the file-size of JPEG images then use the "JPEG Quality" parameter, which is a special feature unique to the JPEG algorithm which allows subjective "quality" to be modified:
This is documented here: http://msdn.microsoft.com/en-us/library/bb882583(v=vs.110).aspx
Copy & paste:
private void VaryQualityLevel()
{
// Get a bitmap.
Bitmap bmp1 = new Bitmap(@"c:\TestPhoto.jpg");
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters);
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestPhotoQualityHundred.jpg", jgpEncoder, myEncoderParameters);
// Save the bitmap as a JPG file with zero quality level compression.
myEncoderParameter = new EncoderParameter(myEncoder, 0L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestPhotoQualityZero.jpg", jgpEncoder, myEncoderParameters);
}
private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}