When I remove the SetColorTable call the image turns out solid black.
Main Topics
Browse All TopicsHello experts,
I have an 8 bit CImage, when I save it into a bitmap or png and check the properties it is an 8 bit bitmap but when I save it as a jpeg it is still 24 bit. Following is code where I create the image and then save a test JPEG BMP and PNG, only the JPEG is 24 bit depth and I need it to be 8.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is a grey scale image, so why are you setting three consecutive bytes inside the inner loop? I should think this would mess up the bmp and png files. You should just set one at a time. Or are you copying from a color image? (What is imgBits?) If copying from a color image, you need to do some conversion from color to grey scale -- I'm not sure what the conversion should be.
Also, you seem to be using unsigned char *, char *, and LPBYTE interchangeably. Be careful about using char * in case it is doing some conversion.
The only application I found so far to actually produce an 8-bit jpeg is gimp, if you open the image then grayscale it and save it again in gimp it produces an 8-bit grayscale jpeg, according to its windows properties. This is the format I need my jpegs to be, the gimp version of the image is attached.
It appears that CImage does not provide a means to specify the type of encoding, but if you start with a 8-bpp indexed grayscale image, it will output a jpg that is in that format. See:
http://www.dotnetmonster.c
Incidently, JPG is a "lossy" format. This shows how to control the quality of of the JPG output:
http://www.bobpowell.net/j
"It appears that CImage does not provide a means to specify the type of encoding, but if you start with a 8-bpp indexed grayscale image, it will output a jpg that is in that format. See:
http://www.dotnetmonster.c
-This currently isn't a problem for me, in this post he wants to atleast make an 8-bit bitmap, my code when saving in BMP format produces an 8-bit BMP fine, or PNG, or GIF, just not JPEG.
"Incidently, JPG is a "lossy" format. This shows how to control the quality of of the JPG output:
http://www.bobpowell.net/j
-JPEG compression for me is fine, only bit-depth is a problem
Also, I use the following calls for CImage:
imagePtr->Create(pdib->biWid
result = imgPtr->Save("C:\\test_JPEG
result = imgPtr->Save("C:\\test_BMP.
result = imgPtr->Save("C:\\test_PNG.
...so CImage DOES provide a means to specify the type of encoding
I meant to say that ("does not provide a means to specify that kind of encoding"); that is, 256-color jpeg-compressed format. It seems to me that if you use 256 colors (or fewer) even when starting with a 24-bit jpeg, then the result will be the same.
I suppose that one thing you could try would be to blit it to a 256-color BMP, then try to sav it as .JPG.
Where did you get the idea that you needed 8bpp JPEG? It's not a normal format.
"Keep in mind that gdi+'s .jpeg encoder will not create a 8bpp .jpeg. It will create a 24bpp
..jpeg image. "
I've never tryied it, but you could look into setting the Encoder.ColorDepth as described (with C# example code) here:
http://msdn.microsoft.com/
They show its use with TIFF format, but the JPEG encoder might also accept that parameter.
Found an open source encoder/decoder, multi-platform, with code examples which can decode/encode 8-Bit Grayscale JPEGS, called TinyJpeg:
http://www.stud.fit.vutbr.
Business Accounts
Answer for Membership
by: dericstonePosted on 2009-09-23 at 12:07:07ID: 25406707
Strange that you are calling SetColorTable on a 8-bit greyscale image. Did you try removing that call?