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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kamaljeet S. (Guest)
on 2009-01-21 01:30
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();
This topic is locked and can not be replied to.