BMP MERGER -- A Reusable Class to Merge BMP files, Load a Bitmap from a BMP File, and Display HBITMAP without Flicker

Environment: Windows 2000 SP2, VC6 SP3
  1. MFC is NOT needed.
  2. A HBITMAP is created from a group of BMP files and the final palette is also returned if needed.
  3. Loads a bitmap from a BMP file; the corresponding palette is also returned.
  4. Displays a bitmap to the given DC without flicker at the given starting point.
  5. Three types of styles can be applied while merging bitmaps. See the images.
    • HORIZONTAL_TILE—This is the default. Aligns all bitmaps horizontally.
    • VERTICAL_TILE—Aligns all bitmaps vertically.
    • MATRIX_TILE—Aligns bitmaps in a matrix style. Gaps are filled with the given background color.
  6. The corresponding palette is also returned if needed; otherwise, it passes NULL if the palette is not needed.
  7. If there are any gaps after merging, they will be filled with the given background color. The default color is BLACK.

To see how the demo works, click the Horizontal, Vertical, and Matrix toolbar buttons. See the following sample source code.

void CBmpLoaderView::OnDraw(CDC* pDC)
{
  CBmpLoaderDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);

  CBitmapMerger BmpMerger;
  int width=0, height=0;
  HPALETTE hPal = NULL;
  HBITMAP hCombBmp = NULL;
  LPCTSTR aFiles[5] = {"Bmp1.bmp", "Bmp2.bmp",
    "Bmp3.bmp", "Bmp4.bmp", "Bmp5.bmp"};
  hCombBmp = BmpMerger.CombineBitmaps(aFiles, 5, &width, &height,
             &hPal, RGB(128,128, 128), g_mode);

  //>> hCombBmp = comb.LoadBitmapFromFile("Bmp4.bmp");

  BmpMerger.DisplayBmp(pDC->GetSafeHdc(), hCombBmp, hPal, 5, 5);

  DeleteObject( hPal );
  DeleteObject( hCombBmp );
}

Downloads

Download demo project - 288 Kb
Download source - 13 Kb


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: July 30, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this upcoming eSeminar that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base …

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds