coco_ score 19
2018/11/16 04:20 投稿
エラーの文章がどこを直せばいいのか分かりません |
### 前提・実現したいこと |
エラーの文章がどこを直せばいいのか分かりません。 |
どなたか分かる方で直すところを教えてください。お願いします。 |
### 発生している問題・エラーメッセージ |
``` |
double z= の式で下記のエラーが出ました。 |
System.Collections.Generic.KeyNotFoundException: '指定されたキーはディレクトリ内に存在しませんでした。' |
``` |
### 該当のソースコード |
```ここに言語名を入力 |
namespace WindowsFormsApp16 |
{ |
public partial class Form1 : Form |
{ |
// 係数用にメンバー変数を定義 |
Dictionary<string, Dictionary<string, Dictionary<string, double>>> keisuu = null; |
/// <summary> |
/// コンストラクタ |
/// </summary> |
public Form1() |
{ |
InitializeComponent(); |
// 係数ファイルを読み込み。 |
try |
{ |
string filepath = @"D:\temp\sample20181025byMH\keisuu_utf8.csv"; |
keisuu = KeisuuReader.Read(filepath, Encoding.UTF8); |
} |
catch (Exception ex) |
{ |
System.Console.WriteLine(ex); |
MessageBox.Show(ex.Message); |
} |
keisuu = new Dictionary<string, Dictionary<string, Dictionary<string, double>>>(); |
// xxxxx1 = 基本色、全色相、活気、評価値の平均 |
keisuu["xxx1"] = new Dictionary<string, Dictionary<string, double>>(); |
keisuu["xxx1"]["a0"] = new Dictionary<string, double>(); |
keisuu["xxx1"]["a0"]["B"] = -0.138; |
keisuu["xxx1"]["a0"]["G"] = -0.137; |
keisuu["xxx1"]["a0"]["P"] = -0.134; |
keisuu["xxx1"]["a0"]["R"] = -0.135; |
keisuu["xxx1"]["a0"]["Y"] = -0.137; |
. |
. |
. |
keisuu["xxx1"]["a5"] = new Dictionary<string, double>(); |
keisuu["xxx1"]["a5"]["B"] = 0.013; |
keisuu["xxx1"]["a5"]["G"] = 0.008; |
keisuu["xxx1"]["a5"]["P"] = 0.017; |
keisuu["xxx1"]["a5"]["R"] = 0.007; |
keisuu["xxx1"]["a5"]["Y"] = 0.010; |
//xxx2 = 基本色、全色相、落ち着き、評価値の平均 |
keisuu["xxx2"] = new Dictionary<string, Dictionary<string, double>>(); |
keisuu["xxx2"]["a0"] = new Dictionary<string, double>(); |
keisuu["xxx2"]["a0"]["B"] = 0.268; |
keisuu["xxx2"]["a0"]["G"] = 0.267; |
keisuu["xxx2"]["a0"]["P"] = 0.265; |
keisuu["xxx2"]["a0"]["R"] = 0.251; |
keisuu["xxx2"]["a0"]["Y"] = 0.258; |
. |
. |
. |
keisuu["xxx2"]["a5"] = new Dictionary<string, double>(); |
keisuu["xxx2"]["a5"]["B"] = 0.003; |
keisuu["xxx2"]["a5"]["G"] = -0.020; |
keisuu["xxx2"]["a5"]["P"] = 0.010; |
keisuu["xxx2"]["a5"]["R"] = -0.017; |
keisuu["xxx2"]["a5"]["Y"] = -0.028; |
// xxx3 = 強調色、全色相、活気、評価値の平均 |
keisuu["xxx3"] = new Dictionary<string, Dictionary<string, double>>(); |
keisuu["xxx3"]["a0"] = new Dictionary<string, double>(); |
keisuu["xxx3"]["a0"]["B"] = 0.044; |
keisuu["xxx3"]["a0"]["G"] = 0.043; |
keisuu["xxx3"]["a0"]["P"] = 0.047; |
keisuu["xxx3"]["a0"]["R"] = 0.047; |
keisuu["xxx3"]["a0"]["Y"] = 0.043; |
. |
. |
. |
keisuu["xxx3"]["a5"] = new Dictionary<string, double>(); |
keisuu["xxx3"]["a5"]["B"] = 0.011; |
keisuu["xxx3"]["a5"]["G"] = 0.007; |
keisuu["xxx3"]["a5"]["P"] = 0.007; |
keisuu["xxx3"]["a5"]["R"] = 0.003; |
keisuu["xxx3"]["a5"]["Y"] = 0.006; |
// xxx4 = 強調色、全色相、落ち着き、評価値の平均 |
keisuu["xxx4"] = new Dictionary<string, Dictionary<string, double>>(); |
keisuu["xxx4"]["a0"] = new Dictionary<string, double>(); |
keisuu["xxx4"]["a0"]["B"] = 0.426; |
keisuu["xxx4"]["a0"]["G"] = 0.427; |
keisuu["xxx4"]["a0"]["P"] = 0.415; |
keisuu["xxx4"]["a0"]["R"] = 0.412; |
keisuu["xxx4"]["a0"]["Y"] = 0.417; |
. |
. |
. |
keisuu["xxx4"]["a5"] = new Dictionary<string, double>(); |
keisuu["xxx4"]["a5"]["B"] = 0.001; |
keisuu["xxx4"]["a5"]["G"] = -0.017; |
keisuu["xxx4"]["a5"]["P"] = -0.004; |
keisuu["xxx4"]["a5"]["R"] = -0.004; |
keisuu["xxx4"]["a5"]["Y"] = -0.014; |
// 文字列定義している場所は変数に入れて使える。 |
/* |
string xxx = "xxx1"; |
string tarColor ="B"; |
double z = keisuu[xxx]["a0"][tarColor] |
+ (keisuu[xxx]["a1"][tarColor] * x) |
+ (keisuu[xxx]["a2"][tarColor] * y) |
+ (keisuu[xxx]["a3"][tarColor] * x * x) |
+ (keisuu[xxx]["a4"][tarColor] * x * y) |
+ (keisuu[xxx]["a5"][tarColor] * y * y); |
*/ |
} |
private void button1_Click(object sender, EventArgs e) |
{ |
// Retrieve the image. |
Bitmap image1 = new Bitmap(@"C:\Users\peanuts\Source\Repos\WindowsFormsApp12\WindowsFormsApp12\Resources\blue.png"); |
//Bitmap image1 = new Bitmap(MAXLINE + 1, MAXLINE +1); // サイズはとても重要(200だったら、201である必要がある) |
int CELL_CNT_x = 100; // 座標1セル当たり100個必要 |
int CELL_CNT_y = 100; // 座標1セル当たり100個必要 |
int BASELINE_x = image1.Width / CELL_CNT_x + 1; // x軸の最大の長さを100等分する |
int BASELINE_y = image1.Height / CELL_CNT_y; // y軸の最大の長さを100等分する |
int x, y; |
string keisuuType = "kkk1"; |
string kanten1 = "xxx1"; |
string kanten2 = "xxx2"; |
string tarColor = "B"; |
string selectedkeisuutype = (comboBoxkeisuuType.SelectedItem.ToString()); |
string selectedtarColor = (comboBox1.SelectedItem.ToString()); |
if ("基本色" == selectedkeisuutype) |
{ |
keisuuType = "kkk1"; |
kanten1 = "xxx1"; |
kanten2 = "xxx2"; |
} |
else if ("強調色" == selectedkeisuutype) |
{ |
keisuuType = "kkk2"; |
kanten1 = "xxx3"; |
kanten2 = "xxx4"; |
} |
if ("青" == selectedtarColor) |
{ |
tarColor = "B"; |
} |
else if ("緑" == selectedtarColor) |
{ |
tarColor = "G"; |
} |
else if ("紫" == selectedtarColor) |
{ |
tarColor = "P"; |
} |
else if ("赤" == selectedtarColor) |
{ |
tarColor = "R"; |
} |
else if ("黄" == selectedtarColor) |
{ |
tarColor = "Y"; |
} |
var graphics = Graphics.FromImage(image1); |
for (x = 0; x <= CELL_CNT_x; x++) |
{ |
for (y = 0; y <= CELL_CNT_y; y++) |
{ |
//float hue = pixelColor.GetHue(); // 色相 |
//float saturation = pixelColor.GetSaturation(); // 彩度を取得 |
//float brightness = pixelColor.GetBrightness(); // 明度を取得 |
if (IsDraw(tarColor, kanten1, kanten2, keisuuType, x, y) == true) |
{ |
int drawX = x * BASELINE_x; // 400 |
int drawY = ReviewGuiY(y * BASELINE_y, image1.Height - 1); // サイズ200の場合,0~199までであるため、最大地199 |
//image1.SetPixel(drawX, drawY, Color.Red); |
graphics.FillEllipse(new SolidBrush(Color.Red), drawX, drawY, BASELINE_x, BASELINE_y); // 塗りつぶす |
} |
} |
} |
// Set the PictureBox to display the image. |
pictureBox1.Image = image1; |
} |
private int ReviewGuiY(int y, int maxY) |
{ |
return maxY - y; |
} |
/// <summary> |
/// X座標とY座標の位置から描画する条件に一致している確認する。 |
/// </summary> |
/// <param name="tarColor">ターゲットカラー</param> |
/// <param name="keisuuType">係数タイプ</param> |
/// <param name="x">明度(saturation)0~100</param> |
/// <param name="y">彩度(brightness)0~100</param> |
/// <returns>出力条件を満たした場合True</returns> |
private bool IsDraw(string tarColor, string kanten1, string kanten2, string keisuuType, float y, float x) |
private bool IsDraw(string tarColor, string kanten1, string kanten2, string keisuuType, float y, float x) |
{ |
double m, n; |
m = double.Parse(textBox1.Text); |
n = double.Parse(textBox2.Text); |
x = x / 10; |
y = y / 10; |
double h = m; // 刻み値 |
double j = n; // 余り範囲 |
// 予測値zを求める |
// 予測式:z=a? +a? x+a? y+a? x2+a? xy+a? y2 |
// x :明度 y :彩度 a ?? ? :係数 z :予測値 |
// 予測式は着色する部分{基本色、強調色}、色相{Blue、Green、Purple、Red、Yellow}、 |
// 観点を表す言葉{にぎやかで活気があること、静かで落ち着きがあること}、 |
// 値の種類{評価値の平均、評価値の標準偏差}ごとに作成する |
// Wは観点の重視度(Tracberツール) |
// double zは活気 z1は落ち着き |
** // double z= の式でエラーが出ました。 |
double z = keisuu[keisuuType][kanten1]["a0"][tarColor] |
+ (keisuu[keisuuType][kanten1]["a1"][tarColor] * x) |
+ (keisuu[keisuuType][kanten1]["a2"][tarColor] * y) |
+ (keisuu[keisuuType][kanten1]["a3"][tarColor] * x * x) |
+ (keisuu[keisuuType][kanten1]["a4"][tarColor] * x * y) |
+ (keisuu[keisuuType][kanten1]["a5"][tarColor] * y * y); |
** |
double z1 = keisuu[keisuuType][kanten2]["a0"][tarColor] |
+ (keisuu[keisuuType][kanten2]["a1"][tarColor] * x) |
+ (keisuu[keisuuType][kanten2]["a2"][tarColor] * y) |
+ (keisuu[keisuuType][kanten2]["a3"][tarColor] * x * x) |
+ (keisuu[keisuuType][kanten2]["a4"][tarColor] * x * y) |
+ (keisuu[keisuuType][kanten2]["a5"][tarColor] * y * y); |
double z2 = z - z1; |
double dAbs = System.Math.Abs(z2); //zの絶対値取得 |
if (dAbs % h <= j) |
{ |
return true; // 何かの条件による計算結果の結果、描画条件を満たした。 |
} |
else |
{ |
return false; // 何かの条件による計算結果の結果、描画上限を満たさなかった。 |
} |
} |
} |
} |
``` |
### 補足情報(FW/ツールのバージョンなど) |
VisualStudio 2017 C# windowsフォームアプリケーション |
coco_ score 19
2018/11/16 04:01 投稿
エラーの文章がどこを直せばいいのか分かりません |
### 前提・実現したいこと |
エラーの文章がどこを直せばいいのか分かりません。 |
どなたか分かる方で直すところを教えてください。お願いします。 |
### 発生している問題・エラーメッセージ |
``` |
double z= の式で下記のエラーが出ました。 |
System.Collections.Generic.KeyNotFoundException: '指定されたキーはディレクトリ内に存在しませんでした。' |
``` |
### 該当のソースコード |
```ここに言語名を入力 |
namespace WindowsFormsApp16 |
{ |
public partial class Form1 : Form |
{ |
// 係数用にメンバー変数を定義 |
Dictionary<string, Dictionary<string, Dictionary<string, double>>> keisuu = null; |
/// <summary> |
/// コンストラクタ |
/// </summary> |
public Form1() |
{ |
InitializeComponent(); |
// 係数ファイルを読み込み。 |
try |
{ |
string filepath = @"D:\temp\sample20181025byMH\keisuu_utf8.csv"; |
keisuu = KeisuuReader.Read(filepath, Encoding.UTF8); |
} |
catch (Exception ex) |
{ |
System.Console.WriteLine(ex); |
MessageBox.Show(ex.Message); |
} |
} |
} |
private void button1_Click(object sender, EventArgs e) |
{ |
// Retrieve the image. |
Bitmap image1 = new Bitmap(@"C:\Users\peanuts\Source\Repos\WindowsFormsApp12\WindowsFormsApp12\Resources\blue.png"); |
//Bitmap image1 = new Bitmap(MAXLINE + 1, MAXLINE +1); // サイズはとても重要(200だったら、201である必要がある) |
int CELL_CNT_x = 100; // 座標1セル当たり100個必要 |
int CELL_CNT_y = 100; // 座標1セル当たり100個必要 |
int BASELINE_x = image1.Width / CELL_CNT_x + 1; // x軸の最大の長さを100等分する |
int BASELINE_y = image1.Height / CELL_CNT_y; // y軸の最大の長さを100等分する |
int x, y; |
string keisuuType = "kkk1"; |
string kanten1 = "xxx1"; |
string kanten2 = "xxx2"; |
string tarColor = "B"; |
string selectedkeisuutype = (comboBoxkeisuuType.SelectedItem.ToString()); |
string selectedtarColor = (comboBox1.SelectedItem.ToString()); |
if ("基本色" == selectedkeisuutype) |
{ |
keisuuType = "kkk1"; |
kanten1 = "xxx1"; |
kanten2 = "xxx2"; |
} |
else if ("強調色" == selectedkeisuutype) |
{ |
keisuuType = "kkk2"; |
kanten1 = "xxx3"; |
kanten2 = "xxx4"; |
} |
if ("青" == selectedtarColor) |
{ |
tarColor = "B"; |
} |
else if ("緑" == selectedtarColor) |
{ |
tarColor = "G"; |
} |
else if ("紫" == selectedtarColor) |
{ |
tarColor = "P"; |
} |
else if ("赤" == selectedtarColor) |
{ |
tarColor = "R"; |
} |
else if ("黄" == selectedtarColor) |
{ |
tarColor = "Y"; |
} |
var graphics = Graphics.FromImage(image1); |
for (x = 0; x <= CELL_CNT_x; x++) |
{ |
for (y = 0; y <= CELL_CNT_y; y++) |
{ |
//float hue = pixelColor.GetHue(); // 色相 |
//float saturation = pixelColor.GetSaturation(); // 彩度を取得 |
//float brightness = pixelColor.GetBrightness(); // 明度を取得 |
if (IsDraw(tarColor, kanten1, kanten2, keisuuType, x, y) == true) |
{ |
int drawX = x * BASELINE_x; // 400 |
int drawY = ReviewGuiY(y * BASELINE_y, image1.Height - 1); // サイズ200の場合,0~199までであるため、最大地199 |
//image1.SetPixel(drawX, drawY, Color.Red); |
graphics.FillEllipse(new SolidBrush(Color.Red), drawX, drawY, BASELINE_x, BASELINE_y); // 塗りつぶす |
} |
} |
} |
// Set the PictureBox to display the image. |
pictureBox1.Image = image1; |
} |
private int ReviewGuiY(int y, int maxY) |
{ |
return maxY - y; |
} |
/// <summary> |
/// X座標とY座標の位置から描画する条件に一致している確認する。 |
/// </summary> |
/// <param name="tarColor">ターゲットカラー</param> |
/// <param name="keisuuType">係数タイプ</param> |
/// <param name="x">明度(saturation)0~100</param> |
/// <param name="y">彩度(brightness)0~100</param> |
/// <returns>出力条件を満たした場合True</returns> |
private bool IsDraw(string tarColor, string kanten1, string kanten2, string keisuuType, float y, float x) |
{ |
double m, n; |
m = double.Parse(textBox1.Text); |
n = double.Parse(textBox2.Text); |
x = x / 10; |
y = y / 10; |
double h = m; // 刻み値 |
double j = n; // 余り範囲 |
// 予測値zを求める |
// 予測式:z=a? +a? x+a? y+a? x2+a? xy+a? y2 |
// x :明度 y :彩度 a ?? ? :係数 z :予測値 |
// 予測式は着色する部分{基本色、強調色}、色相{Blue、Green、Purple、Red、Yellow}、 |
// 観点を表す言葉{にぎやかで活気があること、静かで落ち着きがあること}、 |
// 値の種類{評価値の平均、評価値の標準偏差}ごとに作成する |
// Wは観点の重視度(Tracberツール) |
// double zは活気 z1は落ち着き |
** // double z= の式でエラーが出ました。 |
double z = keisuu[keisuuType][kanten1]["a0"][tarColor] |
+ (keisuu[keisuuType][kanten1]["a1"][tarColor] * x) |
+ (keisuu[keisuuType][kanten1]["a2"][tarColor] * y) |
+ (keisuu[keisuuType][kanten1]["a3"][tarColor] * x * x) |
+ (keisuu[keisuuType][kanten1]["a4"][tarColor] * x * y) |
+ (keisuu[keisuuType][kanten1]["a5"][tarColor] * y * y); |
** |
double z1 = keisuu[keisuuType][kanten2]["a0"][tarColor] |
+ (keisuu[keisuuType][kanten2]["a1"][tarColor] * x) |
+ (keisuu[keisuuType][kanten2]["a2"][tarColor] * y) |
+ (keisuu[keisuuType][kanten2]["a3"][tarColor] * x * x) |
+ (keisuu[keisuuType][kanten2]["a4"][tarColor] * x * y) |
+ (keisuu[keisuuType][kanten2]["a5"][tarColor] * y * y); |
double z2 = z - z1; |
double dAbs = System.Math.Abs(z2); //zの絶対値取得 |
if (dAbs % h <= j) |
{ |
return true; // 何かの条件による計算結果の結果、描画条件を満たした。 |
} |
else |
{ |
return false; // 何かの条件による計算結果の結果、描画上限を満たさなかった。 |
} |
} |
} |
} |
``` |
### 補足情報(FW/ツールのバージョンなど) |
VisualStudio 2017 C# windowsフォームアプリケーション |