
Introduction
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("file:");
splitobj.SplitBitmap(3,3);
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();
ASSERT_VALID(pDoc);
CMemDC dc(pDC);
if(_bmpLoaded)
{
_obj.DrawEntireBitmap(dc,10,300);
_obj.DrawPartOfBitmap(dc,10,10,1,1);
_obj.DrawPartOfBitmap(dc,80,10,2,1);
_obj.DrawPartOfBitmap(dc,150,10,3,1);
_obj.DrawPartOfBitmap(dc,10,80,1,2);
_obj.DrawPartOfBitmap(dc,80,80,2,2);
_obj.DrawPartOfBitmap(dc,150,80,3,2);
_obj.DrawPartOfBitmap(dc,10,150,1,3);
_obj.DrawPartOfBitmap(dc,80,150,2,3);
_obj.DrawPartOfBitmap(dc,150,150,3,3);
_obj.DrawCustomBMP(dc,300,10,100,100,30,30);
}
dc.TextOut(_mouseLoc.x,_mouseLoc.y,
"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.
Conclusion
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
Acknowledgement
I want to thank Keith Rule because I used his CMemDC
class to stop the flickering of the view-window of my demo application.