Solved

WIN32  Copying a BITMAP to a new BITMAP

Posted on 1999-01-05
2
465 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a free software that saves Name Signature drawing to video file 1 69
D3, dragging and rotating. 7 123
VCD to mp4 11 136
Slow Printing 8 71
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.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now