Solved

WIN32  Copying a BITMAP to a new BITMAP

Posted on 1999-01-05
2
469 Views
Last Modified: 2012-08-14
In c/c++ .win32 without using mfc, how can you have a bitmap, and create a new bitmap which contains only a section of the original?

Example:
Original Bitmap 100 X 100 pixels.  I want to create a 20 x 20 bitmap that contains the picture whose top left corner starts at 80,80 on the original bitmap.
0
Comment
Question by:Cov
2 Comments
 
LVL 1

Author Comment

by:Cov
ID: 1113556
Edited text of question
0
 
LVL 2

Accepted Solution

by:
ryanvs earned 20 total points
ID: 1113557
You need to copy the bitmap using BitBlt or StretchBlt to a new bitmap
and memory DC that you create.  Assuming you have an existing Bitmap
handle and DC handle, you would do the following:

HDC hdcMem;           // Memory Device for new bitmap
HBITMAP hbmCopy;      // The new bitmap copy
int xCopyWidth = 20, yCopyHeight = 20;  // New Dimensions
int xWidth = 100, yHeight = 100;  // Original Dimensions
int xStart = 80, yStart = 80;    // Starting Position in Original

hdcMem = CreateCompatibleDC(hdcOrginal);
hbmCopy = CreateCompatibleBitmap(hdcMem, xCopyWidth, yCopyHeight);

SelectObject(hdcMem, hbmCopy);
SetMapMode(hdcMem, GetMapMode(hdcMem));

// Copy Original Bitmap to Bitmap Copy
BitBlt(
        hdcMem,    // Bitmap Copy Memory
        0,         // x Starting Point of Copy
        0,         // y Starting Point of Copy
        xCopyWidth,  // Width of Copy
        yCopyHeight, // Height of Copy
        hdcOriginal, // Device to be copied
        xStart,      // x Starting Point of Source
        yStart,      // y Starting Point of Source
        SRCCOPY);

<....program code....>
// When finished free bitmap and memory space
DeleteObject(hbmCopy);
DeleteDC(hdcMem);


I hope this helps...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question