I’m trying to figure out how to rotate my Bitmap image by an arbitrary degree amount, similar to the solution posted here. However, when I try using this solution, which converts the Bitmap to a Graphics object, and other solutions that I’ve Googled, I keep getting the exception:
A Graphics object cannot be created from an image that has an indexed pixel format.
I need indexed pixels so I can access each pixel and get color information in my program, but I also need the ability to be able to rotate on the fly in degree increments other than 90.
I was wondering if A) there is a solution that is friendly to indexed pixel Bitmaps, or B) if there is a way to temporarily change the Bitmap to allow it to be converted to a Graphics object and then change it back to an indexed pixel Bitmap with the rotation applied?
Thanks much in advance!
EDIT: The PixelFormat for the Bitmap I’m using is “1bppIndexed”.
I used Hans’ solution here: https://stackoverflow.com/a/2016509/1464630
It seems I can still use the same program logic, but it’s no longer in an indexed pixel format so the Graphics class doesn’t complain.