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

**URL:** <https://www.ruby-forum.com/t/possible-to-get-c-code-algorithm-translated-to-ruby-code/158239>\
**Category:** Ruby\
**Created:** [January 21, 2009, 12:30am UTC](https://www.ruby-forum.com/t/possible-to-get-c-code-algorithm-translated-to-ruby-code/158239 "2009-01-21T00:30:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamaljeetsinghsaini](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kamaljeetsinghsaini](https://www.ruby-forum.com/u/kamaljeetsinghsaini)\
**Post date:** [January 21, 2009, 12:30am UTC](https://www.ruby-forum.com/t/possible-to-get-c-code-algorithm-translated-to-ruby-code/158239/1 "2009-01-21T00:30:33Z")

</div>

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);  
}  
}
