@@ -0,0 +1,1683 @@
+%0Apackage net.restlesscoder.sandbox.ui;%0A%0Aimport java.awt.image.BufferedImage;%0A%0Aimport javax.swing.ImageIcon;%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JLabel;%0Aimport javax.swing.WindowConstants;%0A%0Apublic class RenderDoubleArrayAsImage %7B%0A%0A%09/** Generates a gradient image matrix, normalized to %5B0.0, 1.0%5D. */%0A%09public static double%5B%5D%5B%5D generate(final int w, final int h) %7B%0A%09%09final double%5B%5D%5B%5D matrix = new double%5Bh%5D%5Bw%5D;%0A%09%09final double max = (w - 1) * (w - 1) + (h - 1) * (h - 1);%0A%09%09for (int y = 0; y %3C h; y++) %7B%0A%09%09%09for (int x = 0; x %3C w; x++) %7B%0A%09%09%09%09matrix%5By%5D%5Bx%5D = (x * x + y * y) / max;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return matrix;%0A%09%7D%0A%0A%09/** Converts a normalized 2D double matrix to a %7B@link BufferedImage%7D. */%0A%09public static BufferedImage makeBufferedImage(final double%5B%5D%5B%5D matrix) %7B%0A%09%09final int w = matrix%5B0%5D.length, h = matrix.length;%0A%09%09final BufferedImage image = new BufferedImage(w, h,%0A%09%09%09BufferedImage.TYPE_INT_ARGB);%0A%09%09for (int y = 0; y %3C h; y++) %7B%0A%09%09%09for (int x = 0; x %3C w; x++) %7B%0A%09%09%09%09final int v = (int) (255 * matrix%5By%5D%5Bx%5D);%0A%09%09%09%09final int rgb = (255 %3C%3C 24) %7C (v %3C%3C 16) %7C (v %3C%3C 8) %7C v;%0A%09%09%09%09image.setRGB(x, y, rgb);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return image;%0A%09%7D%0A%0A%09/** Displays the given %7B@link BufferedImage%7D in an image window. */%0A%09public static void display(final BufferedImage image) %7B%0A%09%09final JFrame f = new JFrame(%22Image%22);%0A%09%09f.getContentPane().add(new JLabel(new ImageIcon(image)));%0A%09%09f.pack();%0A%09%09f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);%0A%09%09f.setVisible(true);%0A%09%7D%0A%0A%09public static void main(final String... args) throws Exception %7B%0A%09%09final int w = 300, h = 200;%0A%09%09final double%5B%5D%5B%5D matrix = generate(w, h);%0A%0A%09%09final BufferedImage image = makeBufferedImage(matrix);%0A%0A%09%09display(image);%0A%09%7D%0A%7D%0A

Add example code to display double[][] in Swing