Re: Converting a bitmap from 24 bits format to 8 bits format
- From: "Mike Williams" <Mike@xxxxxxxxxxxxxxxxx>
- Date: Mon, 3 Apr 2006 09:44:37 +0100
"Nour" <nour_b@xxxxxxxxxxx> wrote in message news:1144027912.536230.148150@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have read the code provided and ran it but, it seems to me that
there is no conversion as such. I tried to play with the two classes
by passing the pointer from cDIBSection to cDIBSection256 but
it did not work. I must be missing something in my undertstanding?
First you need to create an empty folder somewhere and then unzip the contents of the zip file that you downloaded into that folder. I assume that you've already done that. Then try it out by opening up your copy of VB and loading the pClrDepth6.vbp program from your folder. Then run the program in the VB6 IDE just for initial test purposes.
When the program starts it automatically loads a small jpg file, but just so that you can see for yourself that it has done that you can click the "Load" button and select the "CockSoup.jpg" file yourself. This is a standard full colour jpg (apparently a scan of a real "orient produced" product that the author had discovered somewhere and it had me rolling on the floor laughing!). Well worth the download just to see that image!
Anyway, now click the "256 colour" option button to select your desired output colour depth and then click "Floyd-stucci" option (which is a good choice for normal pictures) and leave the "halftone" option selected. If you now click the "Convert" button the image will be converted to 256 colour and after a short pause the result will be displayed in the picture box. So far the program has performed the conversion but it hasn't saved the result.
To save the result, now click the "Save" button and select an ouput folder / file name (perhaps it would be wise to save it to your desktop just for this test, so select the desktop and use "mypic" as the filename for the time being). You can now close the program down and if you go to your desktop you will see your "mypic.bmp" file. This is the converted result and it is a 256 colour bitmap. You can check this by looking at its pixel size (which is 180 x 223) and its file size (which is 41218 bytes). That's 180 x 223 = 40140 bytes for the pixel data itself (one byte or 8 bits per pixel) with the remaining thousand or so bytes being the header data and the palette data. A full colour (24 bit) bitmap of the same pixel size would be almost three times as big.
So, to use the code (which is admittedly quite complex) in your own programs you don't really need to know a great deal about how it works (although I would advise you to study it carefully untril you do understand it if you have the time). All you need to do is to write your own code to "do the things that the button clicks are doing" automatically, modifying the various routines slightly so that they operaste as you want. For example, you could "hard code" the effect of the "256 colour" and the "Floydd-stucci" buttons into the "Private Sub cmdConvert_Click()" routine and you could hard code an output filename into the "Private Sub cmdSave_Click()" routine and comment out the bits that show the save dialog. It is very easy to use as it stands, and it is also fairsly easy to modify for your own use, and you can do these things without understanding anything at all about how it actually works (if that's what you weant tyo do). However, I would strongly suggest that you take time to study the code to see how it manipulates these DIBSections that it uses. Steve McMahon has done a really excellent job on this code, and you will learn a lot by studying what he has done.
I do understand that you have said you are just a "beginner" in graphics, so perhaps it might be wise to leave the "read and understand" bit on the back burner for a while until you have mastered some of the simpler things you can do with graphics, but I would definitelty recommend that you remember to look at and analyse Steve's code at some time in the future. Very nice stuff.
Mike
.
- Follow-Ups:
- References:
- Converting a bitmap from 24 bits format to 8 bits format
- From: Nour
- Re: Converting a bitmap from 24 bits format to 8 bits format
- From: Mike Williams
- Re: Converting a bitmap from 24 bits format to 8 bits format
- From: Nour
- Converting a bitmap from 24 bits format to 8 bits format
- Prev by Date: Re: VB6, VB2005, or Something Else?
- Next by Date: Re: rich textbox, print lines at bottom of page, how to approach?
- Previous by thread: Re: Converting a bitmap from 24 bits format to 8 bits format
- Next by thread: Re: Converting a bitmap from 24 bits format to 8 bits format
- Index(es):
Loading