title: c# How to convert ushort value into byte so that I can display them in picturebox
body: <pre><code>    public void accessHi3DRange(buffer)
      {
          double meanR = 0;
          uint sumR = 0;
          uint countR = 0;
          int numberOfScansR = buffer.Height;
          bitmapHeight = numberOfScansR;
  
          int subCompWidth = buffer.Components["Hi3D 1"].SubComponents["Range"].Format.Width;
          bitmapWidth = subCompWidth;
          ushort[,] data = buffer.Components["Hi3D 1"].SubComponents["Range"].GetRows&lt;ushort&gt;(0, numberOfScansR);
  
          for (int scan = 0; scan &lt; numberOfScansR; scan++)
          {
  
              for (int col = 0; col &lt; subCompWidth; col++)
              {
                  ushort val = data[scan, col];
                  if (val != 0)
                  {
                      sumR += val;
                      drawPix(col, scan, (int)val, (int)val, (int)val);
                      countR++;
                  }
              }
          }
      }
  
      private void drawPix(int x, int y, int r, int g, int b)
      {
          ((Bitmap)pictureBox1.Image).SetPixel(x, y, Color.FromArgb(r, g, b));
          return;
      }
  </code></pre>
  
  <p>When I run the code I get</p>
  
  <blockquote>
    <p>System.ArgumentException: 'Value of '655' is not valid for 'red'. 'red' should be greater than or equal to 0 and less than or equal to 255.'</p>
  </blockquote>
  
  <p>So to solve this error, am I suppose to convert <code>ushort</code> value into <code>byte</code> so that it can be displayed in picturebox.
  If so, how do I convert? </p>