Change the color of section of a bitmap

I have an application that displays a preview of a CD label I am printing, the preview is a bitmap generated from an external program.  The problem is the the bitmap is square (of course) and the color the external program uses for the background color is white, this works fine for labels that are all blue for example. However labels that have a large amount of white do not look like CD labels at all as the label and the background blend together..

Is there an easy way to convert the white around the edges of the CD as well as the circle in the middle of the cd?
The size of the bitmap will always be the same.  

To phrase another way is there an easy way to pick specific parts of a bitmap and change the color.

LVL 9
JonMnyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AUmidhCommented:
Can you kindly share a sample image of background + label???

0
J1H1W1Commented:
Use the graphics draw and fill methods.
0
JonMnyAuthor Commented:
Attached are two samples the demo.bmp is and example of what I receive after export. The demo2 file is what I want it to look like.

Demo.bmp
demo2.bmp
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

JonMnyAuthor Commented:
Sorry ignore the first file I attached I forgot to change the color setting.

exported.bmp
0
AUmidhCommented:
JonMny:

do you know the radius of the outer circle or any other diemensions or there is any  border of specific color of that circle because your required image has a border but your input image don't have a border...

Give me all the input which you have then i will have a try to your solution.
0
AUmidhCommented:
JonMny:
There is a problem with exported.bmp you attached ....so i use the demo2.bmp as input by making the black color to white... and the demo3.BMP attached...then apply the following algo i got the result attached as demo4.bmp but both the attached files are in jpeg format  i did this for just to reduce size....
hope this seems to solve your problem.. one point is still remain that how to change the color of inner small cricle...that require the radius of that circule and the center point.... take a look at the following algo...

Dim mg1 As New Bitmap("C:\demo3.bmp")
        Dim x As Integer = 0
        Dim y As Integer = 0
        For x = 0 To mg1.Width - 1
            For y = 0 To mg1.Height - 1
                Dim cl As Color = mg1.GetPixel(x, y)
                If cl = Color.FromArgb(255, 254, 254, 254) Or cl = Color.FromArgb(255, 255, 255, 255) Then
                    mg1.SetPixel(x, y, Color.Red)
                Else
                    Exit For
                End If
            Next
        Next
        For y = mg1.Height - 1 To 0 Step -1
            For x = 0 To mg1.Width - 1 Step 1
                Dim cl As Color = mg1.GetPixel(x, y)
                If cl = Color.FromArgb(255, 254, 254, 254) Or cl = Color.FromArgb(255, 255, 255, 255) Or cl = Color.FromArgb(255, 255, 0, 0) Then
                    mg1.SetPixel(x, y, Color.Red)
                Else
                    Exit For
                End If
            Next
        Next
        For y = mg1.Height - 1 To 0 Step -1
            For x = mg1.Width - 1 To 0 Step -1
                Dim cl As Color = mg1.GetPixel(x, y)
                If cl = Color.FromArgb(255, 254, 254, 254) Or cl = Color.FromArgb(255, 255, 255, 255) Or cl = Color.FromArgb(255, 255, 0, 0) Then
                    mg1.SetPixel(x, y, Color.Red)
                Else
                    Exit For
                End If
            Next
        Next
        mg1.Save("C:\demo4.bmp")

apply this...
exported.bmp have indexed file format and you cannot apply SetPixel operation on that...... so that's why i use demo3.bmp derieved from demo2.bmp .... HOPE this give you an idea.
demo3.JPG
demo4.JPG
0
AUmidhCommented:
apply your required color instead of Red.
waiting for your response'''''''''''''''''''''''''''''?
0
AUmidhCommented:
c# version of code.

        Image mg1=new Bitmap("C:\demo3.bmp");
        int x,y;
       for( x = 0; x< mg1.Width - 1;x++)
        {
            for( y = 0;y<mg1.Height - 1;y++)
            {
                Color cl = mg1.GetPixel(x, y);
                if (cl == Color.FromArgb(255, 254, 254, 254)) || (cl == Color.FromArgb(255, 255, 255, 255))
                    mg1.SetPixel(x, y, Color.Red);
                else
                   break;
              }
        }  
      for (y = mg1.Height - 1; y>= 0 y--)
{
            for( x = 0; x< mg1.Width - 1; x++)
{
                Color cl = mg1.GetPixel(x, y);
               if (cl= = Color.FromArgb(255, 254, 254, 254) || cl= = Color.FromArgb(255, 255, 255, 255) || cl = =Color.FromArgb(255, 255, 0, 0) )
                    mg1.SetPixel(x, y, Color.Red);
                else
                    break;
}
}
        for (y = mg1.Height - 1; y>= 0 y--)
{
            for( x = mg1.Width - 1; x>=0;x--)
{
                Color cl = mg1.GetPixel(x, y);
                if (cl= = Color.FromArgb(255, 254, 254, 254) || cl= = Color.FromArgb(255, 255, 255, 255) || cl= = Color.FromArgb(255, 255, 0, 0) )
                    mg1.SetPixel(x, y, Color.Red);
                else
                    break;
}        
}
        mg1.Save("C:\demo4.bmp");
0
JonMnyAuthor Commented:
AUmidh,

The exported.bmp is the actually the file that is exported the other posts have the black lines around the outer circle and the inner circle if the export had this I would be happy.

The code supplied works great for coloring the outer circle.  the work you have done is worth the 500 points can you point me the right direction for getting the circle filled in?
0
AUmidhCommented:
Without that lines i think you will be unable to find out the white area. .....
and for the inner circle you got the radius of the circle and start point .. mean mid point. and if you don't have then may be it is very very difficult [i think]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.