Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WIN32  Copying a BITMAP to a new BITMAP

Posted on 1999-01-05
2
Medium Priority
?
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Author Comment

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

Accepted Solution

by:
ryanvs earned 80 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Suggested Courses

704 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