Solved

convert bitmap color to symbols

Posted on 1998-10-06
2
361 Views
Last Modified: 2010-05-18
HELP ME!!!! I need a C++ source code on converting the bitmap color(RGB value) to symbols when it printed out later.
0
Comment
Question by:nurul_julia
2 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1174607
You could do something like this:

char hex[] = "01234567ABCDEF";
  switch(colornum)
  {
  case 0:                  color="Black";
                                    break;
  case 128:                color="Maroon";
                                    break;
  case 32768:            color="Green";
                                    break;
  case 32896:            color="Olive Green";
                                    break;
  case 8388608:          color="Navy Blue";
                                    break;
  case 8388736:      color="Purple";
                                    break;
  case 8421376:      color="Teal";
                                    break;
  case 8421504:    color="Gray";
                                    break;
  case 12632256:      color="Silver";
                                    break;
  case 255:                  color="Red";
                                    break;
  case 65280:            color="Lime Green";
                                    break;
  case 16711680:   color="Blue";
                                    break;
  case 16711935:   color="Fuchsia";
                                    break;
  case 16776960:   color="Aqua";
                                    break;
  case 16777215:   color="White";
                                    break;
  default:
        color[0]='$';
        int h=colornum;
        for (i=7; i>=0; i--)
          color[i]=hex[(h>>=4)&15];
        color[9]=0;
  }


where colornum is an integer value contain the RGB color,
and color is a string.

If the color is not in the list, it is converted to a hex string.
0
 
LVL 1

Expert Comment

by:pauloserra
ID: 1174608
If you have the RGB values in 32-bit format (it depends on the format of the bitmap, which may be device specific), you can use the macros:
GetBValue(color)
GetGValue(color)
GetRValue(color)
to get the Blue, Green and Red values and format them according to your convenience.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 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

12 Experts available now in Live!

Get 1:1 Help Now