Solved

256color bitmap to 16 color bitmap

Posted on 1997-05-17
5
485 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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Delphi IDE crash without error message ... 7 141
Firemonkey webbrowser scrollbars ? 1 73
Dynamically Created Query 3 81
Delphi problems to abort a printjob 9 51
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 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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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