Solved

Drawing Bitmaps

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 162
computer science syllabus 3 103
gdb doesn't stop on breakpoint 2 114
what type of pointer is this pointer? 3 24
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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