fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. // your code goes here
  8. }
  9.  
  10. // 関数:ノーマル生成
  11. private Bitmap GetNormal()
  12. {
  13. Bitmap bm = new Bitmap(WIDTH, HEIGHT);
  14.  
  15. // 傾斜の強度
  16. int x1 = int.Parse(comboBox1.SelectedItem.ToString()) * -1;
  17. int x2 = int.Parse(comboBox1.SelectedItem.ToString());
  18.  
  19. double dPre, dNow, dNex;
  20. double y1, y2;
  21. int result, r, g, b = 255;
  22. int[,] RN = new int[WIDTH, HEIGHT];
  23. int[,] GN = new int[WIDTH, HEIGHT];
  24.  
  25. // 端の1ピクセルの法線カラーは 127 の固定値に設定
  26. for (int i = 0; i < WIDTH; i++)
  27. {
  28. RN[i, 0] = 127;
  29. GN[i, 0] = 127;
  30. RN[i, HEIGHT - 1] = 127;
  31. GN[i, HEIGHT - 1] = 127;
  32. }
  33. for (int j = 0; j < HEIGHT; j++)
  34. {
  35. RN[0, j] = 127;
  36. GN[0, j] = 127;
  37. RN[WIDTH - 1, j] = 127;
  38. GN[WIDTH - 1, j] = 127;
  39. }
  40.  
  41. // 横方向で法線算出
  42. for (int j = 1; j < HEIGHT - 1; j++)
  43. for (int i = 1; i < WIDTH - 1; i++)
  44. {
  45. dPre = pdataGray[i - 1, j];
  46. dNow = pdataGray[i, j];
  47. dNex = pdataGray[i + 1, j];
  48. y1 = dPre - dNow;
  49. y2 = dNex - dNow;
  50.  
  51. result = GetRadianFrom2Vec(x1, x2, y1, y2);
  52.  
  53. RN[i, j] = result;
  54. }
  55. // 縦方向で法線算出
  56. for (int j = 1; j < HEIGHT - 1; j++)
  57. for (int i = 1; i < WIDTH - 1; i++)
  58. {
  59. dPre = pdataGray[i, j - 1];
  60. dNow = pdataGray[i, j];
  61. dNex = pdataGray[i, j + 1];
  62. y1 = dPre - dNow;
  63. y2 = dNex - dNow;
  64.  
  65. result = GetRadianFrom2Vec(x1, x2, y1, y2);
  66.  
  67. GN[i, j] = result;
  68. }
  69.  
  70. // 法線カラーを適用
  71. for (int j = 0; j < HEIGHT; j++)
  72. for (int i = 0; i < WIDTH; i++)
  73. {
  74. r = 255 - RN[i, j];
  75. g = 255 - GN[i, j];
  76.  
  77. bm.SetPixel(i, j, Color.FromArgb(r, g, b));
  78. }
  79.  
  80. return bm;
  81. }
  82. // 関数:2つのベクトルのなす角度を求める
  83. private int GetRadianFrom2Vec(double x1, double x2, double y1, double y2)
  84. {
  85. double rad1, rad2, rad3;
  86. int result;
  87.  
  88. // X軸ベクトルとのなす角を求める
  89. rad1 = Math.Atan2(y1, x1);
  90. rad2 = Math.Atan2(y2, x2);
  91. // 結果がマイナスの場合にプラスに変換
  92. int i1 = Math.Sign(rad1);
  93. if (i1 == -1) rad1 += (Math.PI * 2);
  94.  
  95. // 90度の補正を入れる(傾斜を法線にするため)
  96. rad1 = rad1 - (Math.PI / 2);
  97. rad2 = rad2 + (Math.PI / 2);
  98.  
  99. // 最終的な角を求める
  100. rad3 = (rad1 + rad2) / 2;
  101.  
  102. // 1πラジアンが1になるよう補正
  103. rad3 = rad3 / Math.PI;
  104. // 8bitの値に変換
  105. result = (int)(rad3 * 255);
  106. result = Math.Max(0, result);
  107. result = Math.Min(255, result);
  108.  
  109. return (result);
  110. }
  111. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(11,11): error CS0246: The type or namespace name `Bitmap' could not be found. Are you missing `System.Drawing' using directive?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty