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: 
The issue with using java will be to get the bytes as ints. While reading in you will need to convert to an int in order to capture values > 127 because java does not have unsigned bytes. 

```
int height=41;
int width=20;
int[] data = {...};

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
for ( int x = 0; x < width; x++ ) {
  for ( int y = 0; y < height; y++ ) {
  // fix this based on your rastering order
  final int c = data[ y * width + x ];
  // all of the components set to the same will be gray
  bi.setRGB(x,y,new Color(c,c,c).getRGB() );
  }
}
File out = new File("image.jpg");
ImageIO.write(bi, "jpg", out);

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

```