Click here to Skip to main content
16,004,782 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionOpen File with default program Pin
marcogja11-May-06 14:01
marcogja11-May-06 14:01 
AnswerRe: Open File with default program Pin
Stephen Hewitt11-May-06 14:34
Stephen Hewitt11-May-06 14:34 
AnswerRe: Open File with default program Pin
Hamid_RT11-May-06 19:03
Hamid_RT11-May-06 19:03 
GeneralRe: Open File with default program Pin
marcogja12-May-06 2:00
marcogja12-May-06 2:00 
GeneralRe: Open File with default program Pin
RicoH12-May-06 4:48
RicoH12-May-06 4:48 
GeneralRe: Open File with default program Pin
marcogja12-May-06 10:50
marcogja12-May-06 10:50 
Questionactivex controls Pin
troythetech11-May-06 12:21
troythetech11-May-06 12:21 
QuestionProblem with grayscale palette Pin
Jim Crafton11-May-06 11:46
Jim Crafton11-May-06 11:46 
I'm trying to create an 8 bit DIB image with a grayscale palette

I create the image like so
char* bmpStruct = new char[ sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 256) ];
bmpInfo_ = (BITMAPINFO*)bmpStruct;
bmpInfo->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bmpInfo->bmiHeader.biWidth = width;		
bmpInfo->bmiHeader.biHeight = -height;
bmpInfo->bmiHeader.biPlanes = 1;
bmpInfo->bmiHeader.biBitCount = 8;
bmpInfo->bmiHeader.biCompression = BI_RGB;
bmpInfo->bmiHeader.biSizeImage = height * width;


I then create the rgb pal colors:
RGBQUAD* colors = &bmpInfo->bmiColors[0];
		
for ( int i=0;i<256;i++ ) {
	colors->rgbBlue = i;
	colors->rgbGreen = i;
	colors->rgbRed = i;
	colors->rgbReserved = 0;
	
	colors ++;
}


A call to CreateDIBSection() then create the bitmap. This works fine. The problem arises when I try and blt the image to an HDC.

As I understand it, I need to create a palette, select it into the dest DC via a call to SelectPalette(), then call RealizePalette, and then to draw the image I call SetDIBitsToDevice(). I do all this, and the image does get drawn, however the colors it uses don't seem to reflect what I put into the palette.

I create the palette with this code:
unsigned char* tmp = new unsigned char[ sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 255) ];

LOGPALETTE* pal = (LOGPALETTE*)tmp;
pal->palNumEntries = 256;
pal->palVersion = 0x300;

PALETTEENTRY* entry = &pal->palPalEntry[0];

for (int i=0;i<pal->palNumEntries-1;i++ ) {
	entry->peRed = bmpInfo.bmiColors[i].rgbRed;
	entry->peGreen = bmpInfo.bmiColors[i].rgbGreen;
	entry->peBlue = bmpInfo.bmiColors[i].rgbBlue;
	entry->peFlags = 0;
	entry ++;
}
HPALETTE palette_ = ::CreatePalette( pal );


This should give me a palette with a smooth gradient from black to white (0 to 255).
When I alter the bits of a the image (I create an image of 256 pix wide and 100 tall) so that the bits of each line range from 0 to 255, I expect to see this smooth gradient, but instead I see a gradient from 0 to 127! Assigning a pixel the value of 255 instead displays an RGB value of 127,127,127. Something stupid is going on, but I just don't get it.


¡El diablo está en mis pantalones! ¡Mire, mire!

Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

SELECT * FROM User WHERE Clue > 0
0 rows returned

Save an Orange - Use the VCF!
AnswerRe: Problem with grayscale palette - SOLVED! Pin
Jim Crafton11-May-06 13:29
Jim Crafton11-May-06 13:29 
QuestionHow To Convert UNICODE to Base64 Pin
benm9999999911-May-06 8:37
benm9999999911-May-06 8:37 
AnswerRe: How To Convert UNICODE to Base64 Pin
led mike11-May-06 10:14
led mike11-May-06 10:14 
GeneralRe: How To Convert UNICODE to Base64 Pin
benm9999999912-May-06 3:31
benm9999999912-May-06 3:31 
GeneralRe: How To Convert UNICODE to Base64 Pin
led mike12-May-06 5:55
led mike12-May-06 5:55 
GeneralRe: How To Convert UNICODE to Base64 Pin
benm9999999915-May-06 7:37
benm9999999915-May-06 7:37 
Question[Message Deleted] Pin
Sachin .S .Potdar11-May-06 8:25
Sachin .S .Potdar11-May-06 8:25 
AnswerRe: RC4 implemantation in VC++ Pin
Chris Losinger11-May-06 8:44
professionalChris Losinger11-May-06 8:44 
AnswerRe: RC4 implemantation in VC++ Pin
ThatsAlok12-May-06 2:03
ThatsAlok12-May-06 2:03 
Questionmsflexgrid Pin
abdoush11-May-06 7:32
abdoush11-May-06 7:32 
QuestionGetting notification of a button being held down Pin
DRHuff11-May-06 7:23
DRHuff11-May-06 7:23 
AnswerRe: Getting notification of a button being held down Pin
Maxwell Chen11-May-06 7:46
Maxwell Chen11-May-06 7:46 
Questionwindow capture Pin
hariramesh11-May-06 5:04
hariramesh11-May-06 5:04 
AnswerRe: window capture Pin
Andy Moore11-May-06 8:33
Andy Moore11-May-06 8:33 
Questionvisual c++ change button code Pin
xcar11-May-06 4:58
xcar11-May-06 4:58 
AnswerRe: visual c++ change button code Pin
toxcct11-May-06 5:00
toxcct11-May-06 5:00 
GeneralRe: visual c++ change button code Pin
Hamid_RT11-May-06 5:11
Hamid_RT11-May-06 5:11 

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.