title: Render from libgdx into a Java Image, completely off-screen
body: <p>I am new to <code>libgdx</code>, and am trying to render (thumbnail-sized) images of ~100 objects from a working game engine into Java <code>Image</code>s that I can display in a <code>Swing</code> application.</p>
  
  <p>I can render them on-screen within a <a href="http://libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/backends/lwjgl/LwjglCanvas.html" rel="nofollow">LwjglCanvas</a> fine, and from there I can grab their pixels using <code>ScreenUtils.getFrameBufferPixels()</code> (trying to pass in a <code>BufferedImage</code>'s <code>getGraphics()</code> into the <code>LwjglCanvas.paint(graphics)</code> method results in nothing being rendered into <code>graphics</code>), and put those into a <code>BufferedImage</code>. However, this requires an existing, displayed <code>LwjglCanvas</code>; I simply cannot figure out how to do background-thread thumbnailing without rendering on-screen.</p>
  
  <p>Attaching current code snippet (requires displayed image within canvas; executed within a <code>Runnable</code> posted to this canvas via <code>canvas.postRunnable()</code>).</p>
  
  <pre><code>// canvas is an LwjglAWTCanvas
  int w = canvas.getGraphics().getWidth();
  int h = canvas.getGraphics().getHeight();
  BufferedImage bi = new BufferedImage(w, h,
          BufferedImage.TYPE_INT_ARGB);
  WritableRaster wr = bi.getRaster();
  byte[] bytes = ScreenUtils.getFrameBufferPixels(0, 0, w, h, false);
  int[] pixel = new int[4];
  for (int y = h-1, b = 0; y &gt;=0 h; y--) {
      for (int x = 0; x &lt; w; x++) {
          pixel[0] = bytes[b++];
          pixel[1] = bytes[b++];
          pixel[2] = bytes[b++];
          pixel[3] = bytes[b++];
          wr.setPixel(x, y, pixel);
      }
  }
  image = bi; // image is the rendered output image
  </code></pre>