Microsoft & .NETVisual BasicImage Compression Using VB

Image Compression Using VB content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Visual Basic Renders any image into a bitmap regardless of the image type mentioned. But it allows the compression of 24 bit images of bitmap type.

Consider a 24 bit bitmapped Image of Size 50 x 50.So there are totally
2500 pixels and each occupying 2500×24 bits, so in case of a bitmap the size can be identified with the resolution.Consider a bitmap image of 50 x 50 with white background and a single point with a color dot.The size of the image will be 2500 x 24 bits. But imagine the level of redundancy in the storage large volume of the size is occupied by the white color which is respresented by &FFFFFF.Image Compression techniques plays its role here in this type of image where the level of redundancy of the image bits are really high.Higher the
redundancy the higher the compression can be achieved. There are different levels of compressions but the major one that is used is called as the runlength encoding.Which follows the following concept.

1 1 1 1 1 1 1 1 1 1 0 0 1 1 1

If the data is stored in the above format it can be rewritten as 10 00 111
ie there are 10 ones in the above list so changed to 10 1 00 111.This is the basic principle of run length Encoding or RLE.

I am using my own algorithm for compression and I am getting a 33% compression for images with enhanced backcolor redundancy.

1)Read all the pixels using point method of the picture box

Load a picture to a picture box ,once the image is loaded to the picture box it can be read as a two dimensional using the scaleheight and scalewidth of the picture box:

	for xaxis= 0 to picturebox.scalewidth
	for yaxis = 0 to picturebox.scaleheight
	next yaxis
	next xaxis

This long value can be stored to a file and second level can be done

2)I call the second level as the Pattern Matching.

Where this 8 digit long integer is replace by a Single number having a help of a lookuptable. Some thing like replace(“166657″,”1”) can be used.


On the Patternmatched data the Encoding can be done.This will give a max of 33% of compression.


Since we follow our own algorithm we need to get the image back using our program only. The decompression can be done on the reverse way using runlength Decoding and pattern rematching. Now the Original image can be obtainted using the pset method of the picture box.

for xaxis= 0 to picturebox.scalewidth
	for yaxis = 0 to picturebox.scaleheight
	next yaxis
	next xaxis

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories