Solved

Drawing Bitmaps

Posted on 2004-04-29
5
420 Views
Last Modified: 2011-04-14
Hi Guys,

Can someone please write some example code to draw a bitmap to the screen in a simple window.  This bitmap must be created in memory (i.e. not from a file) and allow me to write individual pixels to it.  I'm trying to test the speed of gdi vs java 2d.  I have some generic algorithms that i want to port to C++ but I need the above to do it.

Kind Regards,

Chris
0
Comment
Question by:chrisevans123
[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
5 Comments
 
LVL 16

Accepted Solution

by:
George Tokas earned 125 total points
ID: 10952675
In BCB:
Drop a TImage at your form.
Use the following:
TMemoryStream   *MemStream;
Graphics::TBitmap *MyBitmap;
MemStream = new TMemStream;
ThePicture = new Graphics::TBitmap;
MemStream->LoadFromFile("myBitmap");
ThePicture->LoadFromStream(MemStream);
Now you have the bitmap loaded at MemStream(RAM Handle) and also at ThePicture which is a Bitmap allocated buffer.
Using:
TImage(the name of the control on the form)->Picture->Assign(ThePicture);
Display the Bitmap.
You can manipulate ThePicture(Bitmap) and save reload or anything you like.
VC++ is a bit different.

Regards,
gtokas.
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 125 total points
ID: 10958314
The simplest (and well-performing) way to draw bitmap created in memory is using of StretchDIBits function. To use this function you need:

1) Fill BITMAPINFO structure with bitmap parameters (you can use standard RGB bitmap with biBitCount = 24), without color palette.
2) Create array with size 3*w*h bytes (w and h are bitamp width and height). Fill it by some way, setting appropriate R,G and B values (color order in memory is BGR).
3) Call StretchDIBits function to draw bitmap to window device context.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

691 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