Click here to Skip to main content
13,557,288 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 9 Dec 2002

RLE (Run-Length-Encoding) compression routine in MFC for 256 color bitmap

, 9 Dec 2002
Rate this:
Please Sign up or sign in to vote.
A handy MFC class to compress simple 256 color Windows bitmap

Sample Image - RLEBmp.gif


This is a RLE compression routine written in MFC. I wrote this because I could not find handy code for such thing.

RLE compression is useful when saving SIMPLE Windows bitmap. Especially my implementation is rather stupid and not optimized. Therefore, if the source bitmap is complex (like the one in the demo app window shown above), you could even get a bigger bitmap file after compression. :)

The compression routine is wrapped in an MFC bitmap control class, CDVDBitmapControl, which you can put in a dialog conveniently. The usage is easy:

  1. Add a static control (say IDC_STATIC_BITMAP) in the dialog for the bitmap control
  2. Add a #include "DVDBitmapControl.h" in the header file of your dialog
  3. Add a member variable (say m_bmp) of type CDVDBitmapControl in your dialog class.
  4. In OnInitDialog(), add this line: m_bmp.SubclassDlgItem( IDC_STATIC_BITMAP, this);
  5. Call m_bmp.LoadBitmapFile(CString) to load bitmap into control
  6. Call m_bmp.SaveBitmapFile(CString) to save bitmap into 8-bit RLE bitmap

If you need only the compression code, you can extract the CDVDBitmapControl::CompressInRLE8() and CDVDBitmapControl::EndOfLine() routines from DVDBitmapControl.cpp. It is quite straight forward to use them (with some substitutions for bitmap width, bitmap height in code).

I did not write the decompression part because Windows API LoadImage() already does it.

PS: in the demo app, if the loaded bitmap is not in 256 color, [Save] will not work.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Seth Chou
Taiwan Taiwan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWorks when nothing else does Pin
RikTheVeggie2-Nov-11 5:48
memberRikTheVeggie2-Nov-11 5:48 
Generali need a code source for rle Pin
ivanny30-Nov-06 5:04
memberivanny30-Nov-06 5:04 
GeneralRe: i need a code source for rle Pin
indrauday10-Apr-09 22:51
memberindrauday10-Apr-09 22:51 
GeneralHelp!!! Pin
Lerka14-Jan-04 8:56
memberLerka14-Jan-04 8:56 
GeneralRe: Help!!! Pin
ycl9-Mar-04 18:10
memberycl9-Mar-04 18:10 
GeneralAVI RLE compressors Pin
John Ulvr6-Mar-03 11:32
memberJohn Ulvr6-Mar-03 11:32 
GeneralPack them in PNG instead Pin
Kochise10-Dec-02 22:23
sussKochise10-Dec-02 22:23 
GeneralA template-based version Pin
compiler10-Dec-02 9:28
membercompiler10-Dec-02 9:28 
GeneralBe careful! Pin
Anonymous10-Dec-02 2:35
sussAnonymous10-Dec-02 2:35 
GeneralRe: Be careful! Pin
Seth Chou11-Dec-02 2:11
memberSeth Chou11-Dec-02 2:11 
GeneralRe: Be careful! Pin
Kochise11-Dec-02 6:22
sussKochise11-Dec-02 6:22 
GeneralRe: Be careful! Pin
Kochise13-Dec-02 0:06
sussKochise13-Dec-02 0:06 
Generala problem for every student Pin
marc12310-Dec-02 1:21
membermarc12310-Dec-02 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180515.1 | Last Updated 10 Dec 2002
Article Copyright 2002 by Seth Chou
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid