JonMny
asked on
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.
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.
Can you kindly share a sample image of background + label???
Use the graphics draw and fill methods.
ASKER
ASKER
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.
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.
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
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
apply your required color instead of Red.
waiting for your response'''''''''''''''''' '''''''''' '?
waiting for your response''''''''''''''''''
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");
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");
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.