Quantcast
Viewing all articles
Browse latest Browse all 1449

[VB6] Palettize - A VB6 Class for converting StdPicture to 8-bit StdPicture

The main reason you might want this is for creating an 8-bit color or grayscale StdPicture from a StdPicture created by loading an image file. An 8-bit color StdPicture may save "smaller" as a BMP file if required.

Since this also tends to result in a "posterized" image due to the simplistic color quantization algorithm used here, 8-bit color StdPicture creation also handles color depths from 32-colors to the default 256-colors. This might be useful if your goal is posterization or you want an even smaller saved image, but otherwise it is usually pointless.

This is written entirely in VB6 and doesn't require any 3rd party DLLs or even TLBs. It also runs pretty fast.

There are two methods, one for color and one for grayscale (and yes, if you prefer to spell it "grey" feel free to do a replace on the source code). ;)


Palettize.cls is a VB_PredeclaredId = True class, so you do not need to create instances of it to use it. It also depends on the included OList.cls for color palette processing though that helper class is not needed if you delete all of the color processing to keep just the grayscale processing.

There is also a PicSave.cls included in the demo. This is also a VB_PredeclaredId = True class. It can be used to save a StdPicture as BMP, GIF, JPEG, or PNG. Palettize.cls does not need this. You'd only use this sort of thing to save in more formats than just BMP (via plain old VB6 SavePicture).


Image may be NSFW.
Clik here to view.
Name:  sshot.jpg
Views: 31
Size:  36.4 KB


Screenshot of the demo Project


It can benefit from native-compilation optimizations and this demo has the relevant ones turned on. Compile the Project and test the EXE to see it run at full speed.

Most of the size of the attachment is due to a pair of "photographic" sample images. You could change the program to load different images, or replace the two samples by your own for further testing. The demo is just something to test with.

Actual usage is simple: Add OList.cls and Palettize.cls to your VB6 Project. Add PicSave.cls if you want to use that too. Then you can just call the methods of the global predeclared instance Palettize, passing a StdPicture argument and getting a new StdPicture back as the return value.
Attached Images
Image may be NSFW.
Clik here to view.
 
Attached Files

Viewing all articles
Browse latest Browse all 1449

Trending Articles