Screen-Grab : Why only 16 Colours?

In article <>, (Martin R. Hunter) wrote:
}I've noticed a number of threads about 256-colour problems with Delphi.
}I have a program that I want to simply grab the graphics off my own form,  

and blat them to disk (in BMP format).
}The program I've written works... kind of.   It saves the screen in 256

colours, but only the first 16 seem to be visible
}(in paint-shop-pro).        Colours 16-255 disappear and for some reason

become black.

Which means you are not saving RGB values, but logical pallette values.  
Which are reinitialized to null.  The first 20 colors are system colors, but
four overlap.  The rest disappear when the application that created them is
not active.  See the problem?

}Can anyone HELP  ME  out please?     Here's the code :
}           TheFileName - Guess!
}           MainForm - The actual form data is passed
}procedure TGrab.GrabToBMP( TheFileName : TFileName ; MainForm : TForm);
}  MyBitmap     :  TBitmap;   {This'll be created and a copy of the screen
}                             will be splatted to it}
}  CopyRect     :  TRect;     {The size of the window}
}    {Grab window size}
}    CopyRect.Top     :=  0;    CopyRect.Bottom  :=  MainForm.ClientHeight;
}    {Create a new bitmap}
}    MyBitmap := TBitmap.Create;
}    {Make the bitmap the same size as the Form}
}    MyBitmap.Handle := CreateCompatibleBitmap( MainForm.Canvas.Handle ,
}                             MainForm.ClientWidth , MainForm.ClientHeight );
}    {Copy the graphics from the Form to the bitmap}
}    MyBitmap.Canvas.copyrect( CopyRect , MainForm.Canvas , CopyRect );

And here is the problem.  TCanvas retains pointers to the logical pallette,
which hold RGB values and pointers to the hardware pallette.  Try creating a
non-visible TImage component and saving from there.  Also, to actually view
the resulting bitmap in full color you may have to create a pallette, which
requires going through the Windows API.

    The Gentleman

Government is like a baby.  An alimentary c{*word*7}with a big appetite at
one end and no sense of responsibility at the other

-Ronald Reagan