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

K

Kamaljeet Saini

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top