?
Solved

Drawing Bitmaps

Posted on 2004-04-29
5
Medium Priority
?
421 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 375 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 375 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

764 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