Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: two dialogs placing problem? Pin
CPallini30-Oct-07 7:26
mveCPallini30-Oct-07 7:26 
AnswerRe: two dialogs placing problem? Pin
Mark Salsbery30-Oct-07 7:24
Mark Salsbery30-Oct-07 7:24 
GeneralRe: two dialogs placing problem? Pin
led mike30-Oct-07 10:12
led mike30-Oct-07 10:12 
GeneralRe: two dialogs placing problem? Pin
Mark Salsbery30-Oct-07 10:17
Mark Salsbery30-Oct-07 10:17 
GeneralRe: two dialogs placing problem? Pin
led mike30-Oct-07 11:10
led mike30-Oct-07 11:10 
QuestionNumber of Columns used in excel Pin
prithaa30-Oct-07 6:28
prithaa30-Oct-07 6:28 
QuestionI Need some help creating HBITMAP Pin
Miguel Resto30-Oct-07 5:12
Miguel Resto30-Oct-07 5:12 
AnswerRe: I Need some help creating HBITMAP [modified] Pin
Mark Salsbery30-Oct-07 6:49
Mark Salsbery30-Oct-07 6:49 
A few things...

Each row of your pixel data needs to be aligned to a DWORD (4-byte) boundary.
You are fine here with a width of 152.

You are using t in CreateDIBSection incorrectly.  CreateDIBSection returns a
pointer to its pixel bits - it doesn't take a pointer.  Whenever you use a cast like that,
ask yourself if it's correct.  You should never have to explicitly cast a pointer to a void
pointer.

Since your pixel data is 8 bits-per-pixel, you need to have a color table.
Instead of a BITMAPINFOHEADER struct, you can use a BITMAPINFO struct,
constructed with the color table...
BITMAPINFO *pbmi = (BITMAPINFO*)new BYTE[sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 255];

pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
pbmi->bmiHeader.biWidth = 152; 
pbmi->bmiHeader.biHeight = 200; 
pbmi->bmiHeader.biPlanes = 1; 
pbmi->bmiHeader.biBitCount = 8; 
pbmi->bmiHeader.biCompression = BI_RGB; 
pbmi->bmiHeader.biSizeImage = 30400; 
pbmi->bmiHeader.biXPelsPerMeter = 0; 
pbmi->bmiHeader.biYPelsPerMeter = 0; 
pbmi->bmiHeader.biClrUsed = 0; 
pbmi->bmiHeader.biClrImportant = 0; 

for (int i = 0; i < 256; ++i)
{
   pbmi->bmiColors[i].rgbRed = <font color="Red">?</font>;
   pbmi->bmiColors[i].rgbGreen = <font color="Red">?</font>;
   pbmi->bmiColors[i].rgbBlue = <font color="Red">?</font>;
   pbmi->bmiColors[i].rgbReserved = 0;
}

<font color="Red">// You don't really need a DC for CreateDIBSection() unless
//   you're using the system palette.  Not a good idea for saving
//   a bitmap to a file in a device-independent fashion :)
// It's fine here - you could also pass NULL to CreateDIBSection, however.
</font>HDC hdc = ::GetDC(0);

BYTE *pDibBits;
HBITMAP hbitmap = ::CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, &pDibBits, NULL, 0);

<font color="Red">// Copy bits from t to the new DIBsection</font>
memcpy(pDibBits, t, 30400);

::ReleaseDC(0, hdc);
delete[] (BYTE*)pbmi;

... use the DIBsection ...

::DeleteObject(hbitmap);
Each value in the color table should be the RGB value you want to see for a given pixel data byte.


If you want to write a BMP file yourself:

A "packed" BMP file consists of these, in order:

a BITMAPFILEHEADER struct
a BITMAPINFO or BITMAPCOREINFO struct
a color table for bitmap types that require it (yours does)
the pixel bits (rows DWORD aligned)


Mark


Last modified: 11mins after originally posted --


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: I Need some help creating HBITMAP Pin
Miguel Resto30-Oct-07 17:18
Miguel Resto30-Oct-07 17:18 
GeneralRe: I Need some help creating HBITMAP Pin
Nelek30-Oct-07 22:13
protectorNelek30-Oct-07 22:13 
GeneralRe: I Need some help creating HBITMAP Pin
Mark Salsbery31-Oct-07 5:03
Mark Salsbery31-Oct-07 5:03 
Questiongot problem in compiling Pin
scizj30-Oct-07 4:31
scizj30-Oct-07 4:31 
AnswerRe: got problem in compiling Pin
led mike30-Oct-07 4:38
led mike30-Oct-07 4:38 
AnswerRe: got problem in compiling Pin
David Crow30-Oct-07 4:39
David Crow30-Oct-07 4:39 
GeneralRe: got problem in compiling Pin
led mike30-Oct-07 6:02
led mike30-Oct-07 6:02 
AnswerRe: got problem in compiling Pin
Nelek30-Oct-07 22:04
protectorNelek30-Oct-07 22:04 
QuestionNaive Bayes Pin
rarayi30-Oct-07 4:02
rarayi30-Oct-07 4:02 
AnswerRe: Naive Bayes Pin
Nelek30-Oct-07 4:09
protectorNelek30-Oct-07 4:09 
AnswerRe: Naive Bayes Pin
led mike30-Oct-07 4:39
led mike30-Oct-07 4:39 
Questionhow can i forbid anyone else to change the time of the computer? Pin
lostangels30-Oct-07 3:37
lostangels30-Oct-07 3:37 
AnswerRe: how can i forbid anyone else to change the time of the computer? Pin
Nelek30-Oct-07 4:08
protectorNelek30-Oct-07 4:08 
AnswerRe: how can i forbid anyone else to change the time of the computer? Pin
led mike30-Oct-07 4:41
led mike30-Oct-07 4:41 
Questionhelp needed for MFC ritch GUI controls Pin
sarat12in30-Oct-07 3:28
sarat12in30-Oct-07 3:28 
AnswerRe: help needed for MFC ritch GUI controls Pin
Dewm Solo30-Oct-07 3:51
Dewm Solo30-Oct-07 3:51 
AnswerRe: help needed for MFC ritch GUI controls Pin
led mike30-Oct-07 4:43
led mike30-Oct-07 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.