EDN Admin
Well-known member
I tried this but it dosent work.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private Bitmap converttoBlackAndWhite(Bitmap image)
{
<span style="color:Blue; int[,] imageCode = <span style="color:Blue; new <span style="color:Blue; int[image.Width, image.Height]; <span style="color:Green; //The array containing the binaries
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < image.Width; i++)
{
<span style="color:Blue; for (<span style="color:Blue; int j = 0; j < image.Height; j++)
{
Color c = image.GetPixel(i, j);
<span style="color:Blue; if (c.GetBrightness() > 127) <span style="color:Green; //You can change the value
{
imageCode[i, j] = 1; <span style="color:Green; //1 for White
}
<span style="color:Blue; else
{
imageCode[i, j] = 0; <span style="color:Green; //0 for Black
}
}
}
<span style="color:Blue; return image;
}
[/code]
<br/>
I know how to do it with two images and thet third black and white image:
<div style="color:Black;background-color:White; <pre>
Color newColor;
StreamWriter sw = <span style="color:Blue; new StreamWriter(<span style="color:#A31515; @"e:radar_image_close_math_untitled01.txt");
sw.WriteLine(<span style="color:#A31515; "X,Y RGB_Untitled RGB_Radar_Close"+<span style="color:#A31515; " "+<span style="color:#A31515; "Dr"+<span style="color:#A31515; " Dg"+<span style="color:#A31515; " Db"+<span style="color:#A31515; " Color Distance"+Environment.NewLine);
Bitmap newimage1;
Bitmap newimage2;
Bitmap untitled_bmp;
untitled_bmp = <span style="color:Blue; new Bitmap(<span style="color:#A31515; @"e:untitled01.png");
newimage1 = no_clock_and_no_logoArea(untitled_bmp);
Bitmap close_radar_bmp;
close_radar_bmp = <span style="color:Blue; new Bitmap(<span style="color:#A31515; @"e:untitled.png");
newimage2 = no_clock_and_no_logoArea(close_radar_bmp);
Bitmap black_and_white;
black_and_white = <span style="color:Blue; new Bitmap(newimage1.Width, newimage2.Height);
<span style="color:Blue; int x, y;
<span style="color:Blue; for (x = 0; x < black_and_white.Width; x++)
{
<span style="color:Blue; for (y = 0; y < black_and_white.Height; y++)
{
Color originalColor = newimage1.GetPixel(x, y);
Color originalColor1 = newimage2.GetPixel(x, y);
<span style="color:Blue; int WhiteBlack = (<span style="color:Blue; int)((originalColor.R) + (originalColor.G)
+ (originalColor.B));
<span style="color:Blue; int WhiteBlack1 = (<span style="color:Blue; int)((originalColor1.R) + (originalColor1.G)
+ (originalColor1.B));
<span style="color:Blue; if (WhiteBlack == WhiteBlack1)
{
newColor = Color.FromArgb(0, 0, 0);
}
<span style="color:Blue; else
{
newColor = Color.FromArgb(255, 255, 255);
black_and_white.SetPixel(x, y, newColor);
}
}
}
[/code]
<br/>
But i have one image and i want to convert him to black and white.
Thanks. <hr class="sig danieli
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private Bitmap converttoBlackAndWhite(Bitmap image)
{
<span style="color:Blue; int[,] imageCode = <span style="color:Blue; new <span style="color:Blue; int[image.Width, image.Height]; <span style="color:Green; //The array containing the binaries
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < image.Width; i++)
{
<span style="color:Blue; for (<span style="color:Blue; int j = 0; j < image.Height; j++)
{
Color c = image.GetPixel(i, j);
<span style="color:Blue; if (c.GetBrightness() > 127) <span style="color:Green; //You can change the value
{
imageCode[i, j] = 1; <span style="color:Green; //1 for White
}
<span style="color:Blue; else
{
imageCode[i, j] = 0; <span style="color:Green; //0 for Black
}
}
}
<span style="color:Blue; return image;
}
[/code]
<br/>
I know how to do it with two images and thet third black and white image:
<div style="color:Black;background-color:White; <pre>
Color newColor;
StreamWriter sw = <span style="color:Blue; new StreamWriter(<span style="color:#A31515; @"e:radar_image_close_math_untitled01.txt");
sw.WriteLine(<span style="color:#A31515; "X,Y RGB_Untitled RGB_Radar_Close"+<span style="color:#A31515; " "+<span style="color:#A31515; "Dr"+<span style="color:#A31515; " Dg"+<span style="color:#A31515; " Db"+<span style="color:#A31515; " Color Distance"+Environment.NewLine);
Bitmap newimage1;
Bitmap newimage2;
Bitmap untitled_bmp;
untitled_bmp = <span style="color:Blue; new Bitmap(<span style="color:#A31515; @"e:untitled01.png");
newimage1 = no_clock_and_no_logoArea(untitled_bmp);
Bitmap close_radar_bmp;
close_radar_bmp = <span style="color:Blue; new Bitmap(<span style="color:#A31515; @"e:untitled.png");
newimage2 = no_clock_and_no_logoArea(close_radar_bmp);
Bitmap black_and_white;
black_and_white = <span style="color:Blue; new Bitmap(newimage1.Width, newimage2.Height);
<span style="color:Blue; int x, y;
<span style="color:Blue; for (x = 0; x < black_and_white.Width; x++)
{
<span style="color:Blue; for (y = 0; y < black_and_white.Height; y++)
{
Color originalColor = newimage1.GetPixel(x, y);
Color originalColor1 = newimage2.GetPixel(x, y);
<span style="color:Blue; int WhiteBlack = (<span style="color:Blue; int)((originalColor.R) + (originalColor.G)
+ (originalColor.B));
<span style="color:Blue; int WhiteBlack1 = (<span style="color:Blue; int)((originalColor1.R) + (originalColor1.G)
+ (originalColor1.B));
<span style="color:Blue; if (WhiteBlack == WhiteBlack1)
{
newColor = Color.FromArgb(0, 0, 0);
}
<span style="color:Blue; else
{
newColor = Color.FromArgb(255, 255, 255);
black_and_white.SetPixel(x, y, newColor);
}
}
}
[/code]
<br/>
But i have one image and i want to convert him to black and white.
Thanks. <hr class="sig danieli
View the full article