Solved

256color bitmap to 16 color bitmap

Posted on 1997-05-17
5
472 Views
Last Modified: 2010-04-04
how do I convert a 256 color bitmap to 16 color bitmap using Delphi
0
Comment
Question by:bjp
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:gysbert1
ID: 1336373
This is not as simple as you might think. What has to be done is that the 16 most representitive colors out of the 256 be chosen, and the rest be dithered to look good.

Have a look at the API calls assosiated with DrawDib. These calls provide some color conversion for you if necesarry. I cannot have a look at this now since I am on a Linux machine till monday but I am sure it will do the trick.
0
 
LVL 3

Accepted Solution

by:
mheacock earned 100 total points
ID: 1336374
If you want to convert to the 16 system colours (or if you
already know the 16 colours you want to convert to) then the
answer is trivial.

You can view the Windows colour compoents as three-dimensional
space.  Perhaps Red=X, Green=Y, Blue=Z.  Each of your 256
colours has an RGB value.  Each of your 16 colours has an
RGB value.

Viewing colour as 3D space, you simply imagine lines drawn
from each single 256 colour to every 16 colour.

Find the distance from a 256 colour RGB pixel to every 16 colour
RGB.  The shortest distance is the 16 colour RGB to convert to.

The distance formula can be found in any Algebra text book.
Distance = sqrt((R256 - R16)^2 + (G256 - G16)^2 + (B256 - B16)^2)

There are built-in function in Delphi for retrieving the specific
R and G and B values from a pixel...I think they are GetRedValue, GetGreenValue, etc...or something like that.  They are in the
help files.
 
0
 

Author Comment

by:bjp
ID: 1336375
Thanks for your answers. I,m not sure though whether I would have to use the Winapi functions GetDIB etc
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1336376
Why not just the load the bitmap you want to convert into
a TBitmap...you can alter the pixels via its canvas...
0
 

Author Comment

by:bjp
ID: 1336377
Thanks again mheacock, I will try to convert the bitmap to a TBitmap
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now