Board index » delphi » StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit

StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit

Hi

I need to copy a 24-Bit-Image from an Bitmap to TImage or TPaintbox.
But StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit and it
looks awfull.

How can help??

Thanx in advance
Andreas Spang

 

Re:StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit


Quote
Andreas Spang wrote in message <369ef533.746...@news.a-city.de>...
>I need to copy a 24-Bit-Image from an Bitmap to TImage or TPaintbox.
>But StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit and it
>looks awfull.

A high color (15- or 16-bit) or true color (24-bit) bitmap has complete color
information with each pixel.

Each "pixel" of an 8-bit bitmap is really just an index into the palette table.
When you reduce a bitmap from high or true color you need to create a
palette.

In 256 color mode, Windows normally reserves 20 colors so you must
come up with a palette of the best 236 colors for your bitmap.  (And
there is no guarantee that anything else -- other windows or other
bitmaps -- will display correctly once your bitmap is displayed with its palette.)
A 24-bit image can easily have thousands of colors, so it's somewhat of
a trick to get the best 236 colors to display a bitmap.

There is a "Lab Report" in my Computer Lab that shows one way to
get a palette for a 24-bit bitmap for display in 256 color mode:
http://www.efg2.com/lab/graphics/colors/ShowDemoOne.htm

This example takes a 24-bit bitmap and a palette and that's enough
for Windows to display this bitmap.  BUT this example does not take
the final step in the reduction of 24-bits to 8-bits/pixel.  The final step would
involve create a new 8-bits/pixel scanline from each 24-bits/pixel scan.
For each 24-bit pixel the closest "match" in the new palette must be
found and placed in the 8-bits/pixel scanline.  I just haven't found the
time to do this yet.

There is some C++ code that does do this in the Color Quantization
section of my Color page:
http://www.efg2.com/Lab/Library/Color.htm

efg
_________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Re:StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit


In article <369ef533.746...@news.a-city.de>,
  asp...@oasdatic.de (Andreas Spang) wrote:

Quote
> Hi

> I need to copy a 24-Bit-Image from an Bitmap to TImage or TPaintbox.
> But StretchBlt, CopyRect reduce Colors from 16/24 Bit to 8-Bit and it
> looks awfull.

       You must be using an 8-bit display - if the video driver is
set to 256 colors there's no way you're going to get more than
256 on the screen. If you want to do this right you need to choose
a palette somehow and then convert the image to that palette before
display. (I _suspect_ that Windows has no opinion on which palette
to use and is actually converting to 16 colors, making it look
_really_ awful).

       The real solution is to make 256-color displays illegal.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads