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

Discussion in 'Ruby' started by Kamaljeet Saini, Jan 20, 2009.

  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();
    --
    Posted via http://www.ruby-forum.com/.
    Kamaljeet Saini, Jan 20, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    13
    Views:
    651
  2. Lance Riedel

    Translated Offset to Source Offset

    Lance Riedel, Oct 14, 2003, in forum: XML
    Replies:
    2
    Views:
    499
    Patrick TJ McPhee
    Oct 15, 2003
  3. qq2005
    Replies:
    0
    Views:
    360
    qq2005
    Feb 27, 2008
  4. Replies:
    5
    Views:
    393
    Adrienne Boswell
    May 21, 2008
  5. Replies:
    0
    Views:
    1,283
Loading...

Share This Page