Click here to Skip to main content
12,953,065 members (78,153 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 18 Jun 2003

Displaying split Bitmap files

, 18 Jun 2003
Rate this:
Please Sign up or sign in to vote.
CSplitBitmap is a Class to load, split and display BMP files


I was thinking about making a puzzle game. I found in a book, a chapter about using bitmaps, but it was not explained how to display a part of a bitmap, but I knew this was possible. After some searching and reading, I was able to write the CSplitBitmap class.

Using the code

Using the CSplitBitmap class is very simple. Just declare and object.

CSplitBitmap splitobj;

The next thing to do is to load a bitmap image like this:

splitobj.LoadImage("<A href="file:///c://images//foto.jpg">c:\\images\\foto.jpg</A>");
//the next line of code splits the image in 3 x 3 parts. 
//The width and height of these parts are the same

In my example I used the OnDraw() function of the View class to display the image and the other parts.

void CBitmaptestView::OnDraw(CDC* pDC)
    CBitmaptestDoc* pDoc = GetDocument();
    // TODO: add draw code for native data here

    CMemDC dc(pDC);

        //this function is used to display the whole image
        // there the different parts of the 
        //splitted image are drawn in the window
        // part 2,1
        // part 3,1

        // here we select a part of the picture. 300 and 10 are 
        // the x- and y-coordinates of the picture 
        // in the view-window
        // 100 and 100 are the coordinates of the 
        // TopLeft-point were the part starts
        // 30 and 30 are the width and height of the selected part


        "press left mousebutton to load a bmp-file");

Some other functions:

  • long GetBMPHeight(): returns the height of the loaded image.
  • long GetBPWidth(): returns the width of the loaded image.


For the future I was thinking about adding some member functions to alter the width and height of a bitmap. I still didn't figured out how to do it, but I'm sure I can. :p


I want to thank Keith Rule because I used his CMemDC class to stop the flickering of the view-window of my demo application.


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

Web Developer
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

Generaldisply image Pin
Sonipriya14-Feb-07 2:52
memberSonipriya14-Feb-07 2:52 
GeneralRe: disply image Pin
toxcct14-Feb-07 9:21
mvptoxcct14-Feb-07 9:21 
QuestionHow to copy the new Splited part to CBitmap or HBITMAP ? Pin
Manni Singh8-Dec-06 18:44
memberManni Singh8-Dec-06 18:44 
Questionhow can a polygon part of a bitmap be shown Pin
bestwsfz3j18-Dec-05 21:55
memberbestwsfz3j18-Dec-05 21:55 
GeneralDisplaying split Bitmap files Pin
gommir9-May-05 3:59
membergommir9-May-05 3:59 
Generalsplit window Pin
JC Tan4-Jan-04 7:31
sussJC Tan4-Jan-04 7:31 
GeneralNeeds to be tidied up a bit. Pin
WREY22-Jun-03 3:12
memberWREY22-Jun-03 3:12 

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
Web02 | 2.8.170525.1 | Last Updated 19 Jun 2003
Article Copyright 2003 by Franske
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid