#3 – Between e and Pi – The ChangePixelFormatCommand
Enter the ChangePixelFormatCommand. It changes your image’s pixel format. It is available for DotImage Photo, Photo Pro, and Document Imaging.
You may say, “Elaine, why would I use that when I can just call GetChangedPixelFormat from my AtalaImage?” And I would reply, “Ummm… one moment,” and scurry off and ask Steve, and come back and say to you, “Why? Why?! How could you not know that it’s used when chaining commands together?” Sheesh. Some people…
Honestly, campers, I have never used the command until today when putting together this post. It’s very useful if you want to perform a mixture of basic image commands and some of the Advanced Document Cleanup commands (as the ADC commands work best on bi-tonal images). Changing the pixel format is also helpful when trying to reduce the file size of your image. Less bits per pixel will result in less data to save.
Things to note:
- Your new pixel format should not match your old pixel format. Test for this! You’ll receive a nasty ‘Source and destination pixel formats cannot be equal’ exception thrown.
- If you reduce the bits per pixel, you will reduce the available colors in your image. 2 vs. 16 vs. 256 colors…
- Be aware of the alpha channel. If you have it and get rid of it, previously transparent areas may “suddenly” show up.
- 0 means black in grayscale and BGR; 0 means white in CMYK.
- 1 bpp indexed is not necessarily black & white. It just means that you’re using a two-color palette.
Here’s an extreme example of this at work. I am setting the property NewPixelFormat to PixelFormat.1bppIndexed.
Before (image’s pixel format is 24 bits per pixel, BGR):
After (image’s pixel format is 1 bit per pixel):
This reinforces what I said about 1 bpp indexed – my palette here is not black and white, but two shades of gray.
Our next set of commands are going to be all about Channels, otherwise known as playing with colors without paying for mushrooms.