Computer Graphics

Moderators: Sephiroth
Number of threads: 1263
Number of posts: 2665

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Create Bitmap on runtime Posted by qhimq on 29 Jun 2007 at 8:10 AM
Hi,

I'm attempting to use c++, windows api GDI, to create a bitmap of something I painted on the screen. Once I create the bitmap I want to be able to move it about the window.

I couldn't find anything too great on google about it, so I broke down and I'm asking for your help.

If you don't know, possibly if you point me in the direction of a tutorial/code of how to make mspaint, I'd be able to figure it out.

Thanks.
Report
Re: Create Bitmap on runtime Posted by cactus1 on 7 Jul 2007 at 7:53 AM
: Hi,
:
: I'm attempting to use c++, windows api GDI, to create a bitmap of
: something I painted on the screen. Once I create the bitmap I want
: to be able to move it about the window.
:
: I couldn't find anything too great on google about it, so I broke
: down and I'm asking for your help.
:
: If you don't know, possibly if you point me in the direction of a
: tutorial/code of how to make mspaint, I'd be able to figure it out.
:
: Thanks.
:
If you run Windows, the Windows API provides you with several bitmap operations which suit your needs.
http://msdn2.microsoft.com/en-us/library/ms532343.aspx
Report
Re: Create Bitmap on runtime Posted by AsmGuru62 on 8 Jul 2007 at 4:14 AM

1. Get a device context of the area you trying to snap shoot.
- use GetDC()

2. Create a DC compatible with DC from step 1.
- use CreateCompatibleDC()

3. Create a bitmap handle compatible with DC from step 1.
You will need to know the area size (width and height)
- use CreateCompatibleBitmap()

4. Select HBITMAP from step 3 into DC from step 2. You need
to preserve the return value (it is HBITMAP) of this operation.
- use SelectObject()

5. Make a snap shot of the area.
- use BitBlt()
- the source DC is from step 1
- the destination DC is from step 2
- the coordinates and size will define the area itself

6. Restore the HBITMAP in a DC from step 2 - use the returned value
in a call to SelectObject()

7. Get rid of DC from step 2
- use DeleteDC()

===

That's it - at this point you left with HBITMAP created in step 3 and it has the image of the are you need, so you can draw it somewhere else or save it as a file. To save it - you need to do more stuff...

When you finished with HBITMAP - do not forget to dismiss it using DeleteObject() function.
Report
Re: Create Bitmap on runtime Posted by qhimq on 9 Jul 2007 at 5:21 AM
Thanks to both of you.
Report
Re: Create Bitmap on runtime Posted by Josh Code on 11 Jan 2008 at 9:06 AM
: Thanks to both of you.
:
I made a c++ class for working with the bitmap format. It works independent of the Windows API, though.

You can get the c++ source code here:
http://www.programmersheaven.com/d/click.aspx?ID=F54666



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.