Creating a 24-Bit Per Pixel Subregion of a 24-Bit Per Pixel Bitmap

Original Bitmap



Click here for larger image

Subregion of the original bitmap

Environment: VC6

This article shows you how to create a portion of a 24-bit/pixel bitmap at runtime. In order to do this, you must add a 24-bit/pixel bitmap to your resources in VC++, decide what portion of the bitmap you wish (specified by the x-y coordinates of the upper left corner and the horizontal/vertical size of the portion), and what .bmp file you want the new portion of the bitmap to be store. The .bmp file created can be used at a later time, but in addition the bitmap of the subregion can be retrieved and used, for example, in your OnDraw function.

In the following code sample, we create a portion of a huge bitmap. The subregion is 416 by 224 pixels, but the original bitmap is well over 100 times this size.

CBitmapSubRegion bsr;
BOOL bSuccess;
// IDB_BITMAP_SCHUMACHERCAR is a 24-bit/pixel 
// resource ID added to VC++
bSuccess = bsr.SetResourceID(IDB_BITMAP_SCHUMACHERCAR);
if (bSuccess)
{
  bSuccess = bsr.SetFileNameOfResourceBitmap(
                          CString("SchumacherCar.bmp"));
  if (bSuccess)
  {
    // Want to create a subregion which starts at 
    // (x,y) of (259,317) and is 416-pixels wide by 
    // 224-pixels tall
    bSuccess = bsr.SetSubRegionOfBitmap(259,317,416,224);
    if (bSuccess)
    {
      //Set where to store the new bitmap
      bSuccess = bsr.SetFileNameForNewBitmap(
                    CString("SuhumacherCarSubRegion.bmp"));
      if (bSuccess)
      {
        bSuccess = bsr.CreateBitmapOfSubRegion();
        if (bSuccess)
        {
          m_pBitmapSubRegion = 
                           bsr.RetrieveBitmapOfSubRegion();
        }
      }
    }
  }
}

Downloads

Download source - 5 Kb


Comments

  • Getting Linking errors..

    Posted by Legacy on 12/27/2001 12:00am

    Originally posted by: GMR

    BitmapSubRegion.obj : error LNK2001: unresolved external symbol "public: __thiscall CString::~CString(void)" (??1CString@@QAE@XZ)
    BitmapSubRegion.obj : error LNK2001: unresolved external symbol "public: __thiscall CString::CString(void)" (??0CString@@QAE@XZ)
    BitmapSubRegion.obj : error LNK2001: unresolved external symbol "public: static void __stdcall CObject::operator delete(void *,char const *,int)" (??3CObject@@SGXPAXPBDH@Z)................................................................

    Reply
  • Where do I find BitmapCopy.h ? (I'm learning C++) thanks

    Posted by Legacy on 10/24/2001 12:00am

    Originally posted by: Bryan

    Hi, I was able to locate the includes for stdafx.h, but never could find BitmapCopy.h. in any of my library files, is it included in Microsoft VC++ libraries or is it a seperate download? thanks
    I'm new to C++ programming (I've just done some OOP stuff)

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

Top White Papers and Webcasts

  • Live Event Date: November 6, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds