Question: I have run into some problem with Rx. I need that after processing each item in a new thread send result to main thread. I did it with other way. How can i solve this task with Rx? Here is code:

```
 Observable.ToAsync<string, IEnumerable<UserState>>(Run)(path)
 .ObserveOnDispatcher<IEnumerable<UserState>>()
 .Subscribe(
(o) =>
{   // need to run in Main Thread
    foreach (var item in o)
    {
     WriteLog(item.StatusCode, item.Url);
    }                        
},
(ex) =>{        },
() =>{      } );

   // need to run in New Thread
   private IEnumerable<UserState> Run(string sitemap)
   {
 ....
 foreach (var url in urls)
 {
    var result = new UserState
    {
        Url = url.Value,
        TotalItems = urls.Count
    };
    ....
    yield return result;
 }
   }

```

Answer: 
I can answers question 4 and I can give you the code to do this in c#. It is very simple...

```
int width = 20, height = 41;
byte[] grayscale_image = {0, 0, 0, ...};
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height);
int x = 0;
int y = 0;
foreach (int i in grayscale_image)
{
    bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(i, i, i));
    x++;
    if (x >= 41)
    {
        x = 0;
        y++;
    }
}
bitmap.Save("output.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

```

You may also be able to optimise this code if you look around for bitmap optimization techniques (such as locking the bitmap memory)

**EDIT**: Alternative with bit locking (should be much faster)...

NOTE: I am not 100% sure about the PixelFormat used when creating the Bitmap object - was my best guess at the options available.

```
int width = 20, height = 41;
byte[] grayscale_image = {0, 0, 0, ...};
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, PixelFormat.Format8bppIndexed);

System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(
                     new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                     ImageLockMode.WriteOnly, bitmap.PixelFormat);

System.Runtime.InteropServices.Marshal.Copy(bytes, 0, bmpData.Scan0, bytes.Length);

bitmap.UnlockBits(bmpData);

return bitmap;

```
You can just use the ImageIO class in java.

```
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GREY);

Graphics2D g2 = bi.createGraphics();

//loop through and draw the pixels here   

File out = new File("Myimage.jpg");
ImageIO.write(bi, "jpg", out);

```