Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

256color bitmap to 16 color bitmap

Posted on 1997-05-17
5
Medium Priority
?
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 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