Possible to get C# code/algorithm translated to Ruby code


#1

Can someone please help in translating the following C# code to Ruby
code.The following code bascially is reading data from a “.text” binary
data file and then turns that into “.bmp” image of 24 bit.

           Bitmap myNewBmp = new Bitmap(704, 480,

PixelFormat.Format24bppRgb);
//FileStream fs = File.Open(@“C:\NEW\image1.text”,
FileMode.Open);
FileStream fs = File.Open(@“C:\image1.text”,
FileMode.Open);

            BinaryReader br = new BinaryReader(fs);
            Graphics g = Graphics.FromImage(myNewBmp);

            for (int i = 0; i < bufferscreen_height; i++)
            {
                for (int j = 0; j < bufferscreen_width; j++)
                {
                    ushort lPixel = (ushort)br.ReadInt16();
                    //byte ca = (byte)(lPixel >> 15);
                    byte cr = (byte)((lPixel << 17) >> 27);
                    byte cg = (byte)((lPixel << 22) >> 27);
                    byte cb = (byte)((lPixel << 27) >> 27);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(cr
  • 8 % 256, cg * 8 % 256, cb * 8 % 256)), j, i, 1, 1);
    }
    }

              //string fileName = @"C:\NEW\image1.bmp"+filextn;
              string fileName = @"C:\\image1.bmp"; // +filextn;
              //render the image to the picture box
              myNewBmp.Save(fileName, ImageFormat.Bmp);
              br.Close();
              fs.Close();