Solved

256color bitmap to 16 color bitmap

Posted on 1997-05-17
5
483 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 65
Tembedded WB animatid gifs not animated on some pcs 2 84
Delphi: barcode reading on android platform 1 53
Twebbrowser add css to the header 3 29
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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