Solved

Drawing Bitmaps

Posted on 2004-04-29
5
413 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
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

16 Experts available now in Live!

Get 1:1 Help Now