Solved

Drawing Bitmaps

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

810 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