Thread: Loading Subsections of Bitmaps

  1. #1
    I lurk
    Join Date
    Aug 2002

    Loading Subsections of Bitmaps

    Is there any Win32 API function that will allow me to load a subsection of a bitmap (specifying width, height, and x,y) without resorting to directly manipulating the bitmapped data?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Get the current screen DC. Create a memory DC which is compatible with the screen DC. Create a compatible bitmap. Load your bitmap into the memory DC and use BitBlt() to copy whichever rectangles you want.

    Lookup GetDC(), CreateCompatibleDC(), CreateCompatibleBitmap(), SelectObject(), BitBlt(), ReleaseDC(), DeleteDC(), DeleteObject().
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    Adrian is right but you need two DC's. One for the final image and one temp.

    If you want you can create the DC as Adrian says, then just select the BMP into it (catching the return) rather than creating a compatible bitmap.

    Then use BitBlt() or the less satisfactory StretchBlt() to copy the relevent section to your framebuffer DC.

    Reselect the original BMP and clean up the GDI's.

    I find GetObject() is handy to find the dimensions of the BMP.


    iWidth=BMP.bmWidth;// ect
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Loading Bitmaps in Allegro
    By LiNeAr in forum Game Programming
    Replies: 1
    Last Post: 08-15-2005, 04:12 PM
  2. Loading bitmaps with createfile() +CreateDIBSection
    By Stevo in forum Windows Programming
    Replies: 7
    Last Post: 05-13-2004, 09:22 PM
  3. Loading bitmaps without win32
    By /Muad'Dib\ in forum C++ Programming
    Replies: 0
    Last Post: 04-05-2004, 02:47 PM
  4. trouble loading bitmaps in allegro
    By bobish in forum Game Programming
    Replies: 10
    Last Post: 02-28-2002, 06:07 PM
  5. Loading Bitmaps
    By Neandrake in forum Windows Programming
    Replies: 4
    Last Post: 12-17-2001, 01:50 AM