EDN Admin
Well-known member
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.IO;
<span style="color:Blue; namespace GetImagesInformation
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Green; // The text file to remove from the compare loop here. Then to create a text file with a list from the two compared files and the new fixed filtered black and white file.
Color newColor;
StreamWriter sw = <span style="color:Blue; new StreamWriter(<span style="color:#A31515; @"e:radar_image_close_math.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:radar001816.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);
}
}
}
black_and_white.Save(<span style="color:#A31515; @"e:radar_image_close&radar_untitled.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
<span style="color:Blue; double highestDouble = 0;
<span style="color:Blue; double color_distance;
Bitmap filtered_image;
filtered_image = <span style="color:Blue; new Bitmap(black_and_white);
<span style="color:Blue; int b,c;
<span style="color:Blue; for (b = 0; b < filtered_image.Width; b++)
{
<span style="color:Blue; for (c = 0; c < filtered_image.Height; c++)
{
Color Color1 = filtered_image.GetPixel(b, c);
Color originalColor = newimage1.GetPixel(b, c);
Color originalColor1 = newimage2.GetPixel(b, c);
<span style="color:Blue; if (Color1.R == 0 && Color1.G == 0 && Color1.B == 0)
{
}
<span style="color:Blue; else
{
<span style="color:Blue; double Dr = originalColor.R - originalColor1.R;
<span style="color:Blue; double Dg = originalColor.G - originalColor1.G;
<span style="color:Blue; double Db = originalColor.B - originalColor1.B;
color_distance = Math.Sqrt(Dr * Dr + Dg * Dg + Db * Db);
<span style="color:Blue; double[] d = { color_distance };
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < d.Length; i++)
{
<span style="color:Blue; if (highestDouble < d)
{
highestDouble = d;
}
}
sw.WriteLine(b.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; "," + c.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " + <span style="color:#A31515; "A_" + originalColor.A.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " R_" + originalColor.R.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " G_" + originalColor.G.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " B_" + originalColor.B.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " +
<span style="color:#A31515; "A_" + originalColor1.A.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " R_" + originalColor1.R.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " G_" + originalColor1.G.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " B_" + originalColor1.B.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " +
<span style="color:#A31515; "Dr " + Dr.ToString(<span style="color:#A31515; "D2") + <span style="color:#A31515; " Dg " + Dg.ToString(<span style="color:#A31515; "D1") + <span style="color:#A31515; " Db " + Db.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " Color Distance "+<span style="color:Blue; string.Format(<span style="color:#A31515; "{0:0.0}", color_distance));
}
}
}
sw.WriteLine(Environment.NewLine+<span style="color:#A31515; " Highest color distance " + highestDouble);
sw.Close();
}
<span style="color:Blue; public <span style="color:Blue; static Bitmap no_clock_and_no_logoArea(Bitmap original_radar_image)
{
<span style="color:Blue; int image_clock_area_x = 0;
<span style="color:Blue; int image_clock_area_y = 0;
<span style="color:Blue; int image_clock_area_x1 = 140;
<span style="color:Blue; int image_clock_area_y1 = 21;
<span style="color:Blue; int b, c;
<span style="color:Blue; int image_logo_area_x = 421;
<span style="color:Blue; int image_logo_area_y = 414;
<span style="color:Blue; int image_logo_area_x1 = 91;
<span style="color:Blue; int image_logo_area_y1 = 98;
Bitmap newimage;
newimage = <span style="color:Blue; new Bitmap(original_radar_image);
<span style="color:Blue; int x, y;
<span style="color:Blue; for (x = image_logo_area_x; x < image_logo_area_x + image_logo_area_x1; x++)
{
<span style="color:Blue; for (y = image_logo_area_y; y < image_logo_area_y + image_logo_area_y1; y++)
{
Color logo_color = original_radar_image.GetPixel(x, y);
newimage.SetPixel(x, y, Color.Black);
}
}
<span style="color:Blue; for (b = image_clock_area_x; b < image_clock_area_x + image_clock_area_x1; b++)
{
<span style="color:Blue; for (c = image_clock_area_y; c < image_clock_area_y + image_clock_area_y1; c++)
{
Color clock_color = original_radar_image.GetPixel(b, c);
newimage.SetPixel(b, c, Color.Black);
}
}
<span style="color:Green; //newimage.Save(@"e:radar_noClock_noLogo.png", System.Drawing.Imaging.ImageFormat.Png);
<span style="color:Blue; return newimage;
}
}
}
<span style="color:Green; // To change the project/solution name from Math to ComparingImages...etc to thkni about a name \
[/code]
I changed this 3 variuables to double:
double Dr = originalColor.R - originalColor1.R;<br/>
double Dg = originalColor.G - originalColor1.G;<br/>
double Db = originalColor.B - originalColor1.B;
Before the change it was:
int Dr = (int)originalColor.R - originalColor1.R;<br/>
int Dg = (int)originalColor.G - originalColor1.G;<br/>
int Db = (int)originalColor.B - originalColor1.B;
When it was int the line sw.WriteLine was working without a problem.
But as i changed to double im getting error marked with yellow on the line:
sw.WriteLine(b.ToString("D3") + "," + c.ToString("D3") + " " + "A_" + originalColor.A.ToString("D3") + " R_" + originalColor.R.ToString("D3") + " G_" + originalColor.G.ToString("D3") + " B_" + originalColor.B.ToString("D3")
+ " " +<br/>
"A_" + originalColor1.A.ToString("D3")
+ " R_" + originalColor1.R.ToString("D3") + " G_" + originalColor1.G.ToString("D3") + " B_" + originalColor1.B.ToString("D3") + " " +<br/>
"Dr " + Dr.ToString("D2")
+ " Dg " + Dg.ToString("D1") + " Db " + Db.ToString("D3") + " Color Distance "+string.Format("{0:0.0}",
color_distance));
The error say: Format specifier was invalid
System.FormatException was unhandled<br/>
Message=Format specifier was invalid.<br/>
Source=mscorlib<br/>
StackTrace:<br/>
at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)<br/>
at System.Double.ToString(String format)<br/>
at GetImagesInformation.Program.Main(String[] args) in D:C-SharpConsole-Application-ProjectsGetImagesInformationGetImagesInformationGetImagesInformationProgram.cs:line 105<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException:
Why when i changed it to double its giving me this erorr ?
Thanks. <hr class="sig danieli
View the full article
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.IO;
<span style="color:Blue; namespace GetImagesInformation
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Green; // The text file to remove from the compare loop here. Then to create a text file with a list from the two compared files and the new fixed filtered black and white file.
Color newColor;
StreamWriter sw = <span style="color:Blue; new StreamWriter(<span style="color:#A31515; @"e:radar_image_close_math.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:radar001816.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);
}
}
}
black_and_white.Save(<span style="color:#A31515; @"e:radar_image_close&radar_untitled.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
<span style="color:Blue; double highestDouble = 0;
<span style="color:Blue; double color_distance;
Bitmap filtered_image;
filtered_image = <span style="color:Blue; new Bitmap(black_and_white);
<span style="color:Blue; int b,c;
<span style="color:Blue; for (b = 0; b < filtered_image.Width; b++)
{
<span style="color:Blue; for (c = 0; c < filtered_image.Height; c++)
{
Color Color1 = filtered_image.GetPixel(b, c);
Color originalColor = newimage1.GetPixel(b, c);
Color originalColor1 = newimage2.GetPixel(b, c);
<span style="color:Blue; if (Color1.R == 0 && Color1.G == 0 && Color1.B == 0)
{
}
<span style="color:Blue; else
{
<span style="color:Blue; double Dr = originalColor.R - originalColor1.R;
<span style="color:Blue; double Dg = originalColor.G - originalColor1.G;
<span style="color:Blue; double Db = originalColor.B - originalColor1.B;
color_distance = Math.Sqrt(Dr * Dr + Dg * Dg + Db * Db);
<span style="color:Blue; double[] d = { color_distance };
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < d.Length; i++)
{
<span style="color:Blue; if (highestDouble < d)
{
highestDouble = d;
}
}
sw.WriteLine(b.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; "," + c.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " + <span style="color:#A31515; "A_" + originalColor.A.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " R_" + originalColor.R.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " G_" + originalColor.G.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " B_" + originalColor.B.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " +
<span style="color:#A31515; "A_" + originalColor1.A.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " R_" + originalColor1.R.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " G_" + originalColor1.G.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " B_" + originalColor1.B.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " " +
<span style="color:#A31515; "Dr " + Dr.ToString(<span style="color:#A31515; "D2") + <span style="color:#A31515; " Dg " + Dg.ToString(<span style="color:#A31515; "D1") + <span style="color:#A31515; " Db " + Db.ToString(<span style="color:#A31515; "D3") + <span style="color:#A31515; " Color Distance "+<span style="color:Blue; string.Format(<span style="color:#A31515; "{0:0.0}", color_distance));
}
}
}
sw.WriteLine(Environment.NewLine+<span style="color:#A31515; " Highest color distance " + highestDouble);
sw.Close();
}
<span style="color:Blue; public <span style="color:Blue; static Bitmap no_clock_and_no_logoArea(Bitmap original_radar_image)
{
<span style="color:Blue; int image_clock_area_x = 0;
<span style="color:Blue; int image_clock_area_y = 0;
<span style="color:Blue; int image_clock_area_x1 = 140;
<span style="color:Blue; int image_clock_area_y1 = 21;
<span style="color:Blue; int b, c;
<span style="color:Blue; int image_logo_area_x = 421;
<span style="color:Blue; int image_logo_area_y = 414;
<span style="color:Blue; int image_logo_area_x1 = 91;
<span style="color:Blue; int image_logo_area_y1 = 98;
Bitmap newimage;
newimage = <span style="color:Blue; new Bitmap(original_radar_image);
<span style="color:Blue; int x, y;
<span style="color:Blue; for (x = image_logo_area_x; x < image_logo_area_x + image_logo_area_x1; x++)
{
<span style="color:Blue; for (y = image_logo_area_y; y < image_logo_area_y + image_logo_area_y1; y++)
{
Color logo_color = original_radar_image.GetPixel(x, y);
newimage.SetPixel(x, y, Color.Black);
}
}
<span style="color:Blue; for (b = image_clock_area_x; b < image_clock_area_x + image_clock_area_x1; b++)
{
<span style="color:Blue; for (c = image_clock_area_y; c < image_clock_area_y + image_clock_area_y1; c++)
{
Color clock_color = original_radar_image.GetPixel(b, c);
newimage.SetPixel(b, c, Color.Black);
}
}
<span style="color:Green; //newimage.Save(@"e:radar_noClock_noLogo.png", System.Drawing.Imaging.ImageFormat.Png);
<span style="color:Blue; return newimage;
}
}
}
<span style="color:Green; // To change the project/solution name from Math to ComparingImages...etc to thkni about a name \
[/code]
I changed this 3 variuables to double:
double Dr = originalColor.R - originalColor1.R;<br/>
double Dg = originalColor.G - originalColor1.G;<br/>
double Db = originalColor.B - originalColor1.B;
Before the change it was:
int Dr = (int)originalColor.R - originalColor1.R;<br/>
int Dg = (int)originalColor.G - originalColor1.G;<br/>
int Db = (int)originalColor.B - originalColor1.B;
When it was int the line sw.WriteLine was working without a problem.
But as i changed to double im getting error marked with yellow on the line:
sw.WriteLine(b.ToString("D3") + "," + c.ToString("D3") + " " + "A_" + originalColor.A.ToString("D3") + " R_" + originalColor.R.ToString("D3") + " G_" + originalColor.G.ToString("D3") + " B_" + originalColor.B.ToString("D3")
+ " " +<br/>
"A_" + originalColor1.A.ToString("D3")
+ " R_" + originalColor1.R.ToString("D3") + " G_" + originalColor1.G.ToString("D3") + " B_" + originalColor1.B.ToString("D3") + " " +<br/>
"Dr " + Dr.ToString("D2")
+ " Dg " + Dg.ToString("D1") + " Db " + Db.ToString("D3") + " Color Distance "+string.Format("{0:0.0}",
color_distance));
The error say: Format specifier was invalid
System.FormatException was unhandled<br/>
Message=Format specifier was invalid.<br/>
Source=mscorlib<br/>
StackTrace:<br/>
at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)<br/>
at System.Double.ToString(String format)<br/>
at GetImagesInformation.Program.Main(String[] args) in D:C-SharpConsole-Application-ProjectsGetImagesInformationGetImagesInformationGetImagesInformationProgram.cs:line 105<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException:
Why when i changed it to double its giving me this erorr ?
Thanks. <hr class="sig danieli
View the full article