I get an image screenshot as a byte array. How do I convert this image to a lower bit image so as to reduce size? There are only 10 colors in the whole image so I think there must be some workaround to do this. Any hints?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can save it as a palettized image file. Assuming your image is held in a variable
bmpof typeBitmap.mStreamis aMemoryStreamin this case so you can store it in memory:The gif format support various palette sizes up-to 256 colors as it uses bitplanes rather than RGB-buffers. In your case it would probably be saved as a 16 color file. The GIF uses LZW compression so the resulting files tend to be small in size.
There is also PNG-8 format which do approximately the same as with the GIF.
To recall initialize a Bitmap with:
Unfortunately you cannot create a Graphics object with indexed bitmaps – otherwise the logic approach would be to copy the data from screen into a bitmap of pixel format
PixelFormat.Format4bppIndexed.However, creating a Graphics on a bitmap in indexed format will raise an exception – basically you will need to convert and copy the data manually. Therefor my suggestion in this answer will probably be more convenient if the image isn’t needed frequently.