A simple technique for compressing an image is run-length encoding. The color of each pixel or area is specified for an image. The color pallette can be specified by the first letter of each color (R, G, B, C, M, Y, K, W) - red, green, blue, cyan, magenta, yellow, black, white. An example 6 by 4 image is:
RRRGGGYYYYWBWWRGBBBBBRRRRun-length encoding counts the number of each color in a group and replaces the individual color values by a number and the color. For our example, this would give:
compressImage method to run-length compress a
string of characters.