前提・実現したいこと
エラーの文章がどこを直せばいいのか分かりません。
どなたか分かる方で直すところを教えてください。お願いします。
発生している問題・エラーメッセージ
double z= の式で下記のエラーが出ました。 System.Collections.Generic.KeyNotFoundException: '指定されたキーはディレクトリ内に存在しませんでした。'
該当のソースコード
namespace WindowsFormsApp16 { public partial class Form1 : Form { 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; } 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; // 余り範囲 ** // 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フォームアプリケーション

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/18 02:34