Solved

WIN32  Copying a BITMAP to a new BITMAP

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Skew Text In Photoshop 11 1,901
Animation / Modelling 8 96
directx diagnostic tool help dialog removal vista 12 155
Simple 3D CAD 18 109
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…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

773 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