[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1469
  • Last Modified:

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.

0
JonMny
Asked:
JonMny
  • 6
  • 3
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now