Click here to Skip to main content
16,017,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a image of surfboard(i.e. the object i have to color) (in any format)..
I want to set color to surfboard only.
Also I have to add border to surfboard with different color.
C#
public static Bitmap setColour(string NewFileName) 
{ 
   ColorDialog cDia = new ColorDialog(); 
   if (cDia.ShowDialog() == DialogResult.OK) 
   { 
     Graphics NewGraphics = Graphics.FromImage(NewBitmap); 
     float[][] FloatColorMatrix = { new float[] { float.Parse(cDia.Color.R.ToString())/255,0,0,0,0}, new float[] { 0,float.Parse(cDia.Color.G.ToString())/255,0,0,0}, new float[] { 0,0,float.Parse(cDia.Color.B.ToString())/255,0,0}, new float[] { 0,0,0,1,0 }, new float[] { 0.11F,0.0F,0.0F,0.0F,1} }; 
     ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
     ImageAttributes Attributes = new ImageAttributes(); 
     Attributes.SetColorMatrix(NewColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default); 
     NewGraphics.DrawImage(NewBitmap, new Rectangle(0, 0, NewBitmap.Width, NewBitmap.Height), 0, 0, NewBitmap.Width, NewBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes); 
     NewGraphics.Dispose(); 
   } 
   return NewBitmap; 
}


Please help me for this..
Posted
Updated 16-Jun-10 6:27am
v2
Comments
LittleYellowBird 16-Jun-10 8:41am    
Hi, I suggested in answer to your last question that you describe your problem better but sadly I think there is still insufficient information. It is not even clear if this is project that you have started or just an idea. Try to explain exactly what you need help with in a Question. Best of Luck :-)
Sandip Dhage 16-Jun-10 8:53am    
currently I m converting image into bitmap and using graphics object applying color matrix over it..
But doing this all image color is change but i want to change only color of real object in the image..
Following is the code i have done..
Plz correct my solution or suggest me other proper solution for it..

public static Bitmap setColour(string NewFileName)
{
ColorDialog cDia = new ColorDialog();
if (cDia.ShowDialog() == DialogResult.OK)
{

Graphics NewGraphics = Graphics.FromImage(NewBitmap);

float[][] FloatColorMatrix =
{
new float[] { float.Parse(cDia.Color.R.ToString())/255,0,0,0,0},
new float[] { 0,float.Parse(cDia.Color.G.ToString())/255,0,0,0},
new float[] { 0,0,float.Parse(cDia.Color.B.ToString())/255,0,0},
new float[] { 0,0,0,1,0 },
new float[] { 0.11F,0.0F,0.0F,0.0F,1}


};



ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
ImageAttributes Attributes = new ImageAttributes();
Attributes.SetColorMatrix(NewColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
NewGraphics.DrawImage(NewBitmap, new Rectangle(0, 0, NewBitmap.Width, NewBitmap.Height), 0, 0, NewBitmap.Width, NewBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes);
NewGraphics.Dispose();


}
return NewBitmap;
}

and returing bitmap is set to picturebox...
LittleYellowBird 16-Jun-10 9:27am    
Hi, this is a much better question but by putting it in a comment it is really hard to read, so put it in a NEW Question, with the code formated properly and we'll see if either I or someone else can help. Cheers. :-)
Sandeep Mewara 16-Jun-10 12:28pm    
Updated your question with your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900