Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

256color bitmap to 16 color bitmap

Posted on 1997-05-17
5
Medium Priority
?
491 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

963 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