Package eu.hoefel
Class ArrayToPNG
- java.lang.Object
-
- eu.hoefel.ArrayToPNG
-
public class ArrayToPNG extends Object
Convert a 2d array into a PNG image.- Author:
- Udo Hoefel
-
-
Field Summary
Fields Modifier and Type Field Description static double[][]COLORMAP1Default jet-like colormap for use with array2Image and dumpAsPng.
-
Constructor Summary
Constructors Constructor Description ArrayToPNG()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BufferedImagearray2Image(float[][] a, double[][] colormap, double[][] alpha, boolean interpolatedColors)Creates an image from an array using a specified (optional) colormap and (optional) transparency alpha.static voiddumpAsPng(float[][] a, double[][] colormap, double[][] alpha, String filename, boolean interpolatedColors)Dumps the array as a png file, using a specified (optional) colormap and (optional) transparency alpha.static voiddumpAsPng(float[][] a, String filename)Dumps the array as a png file'
-
-
-
Method Detail
-
dumpAsPng
public static void dumpAsPng(float[][] a, String filename)Dumps the array as a png file'- Parameters:
a- The arrayfilename- The name of the image file.
-
dumpAsPng
public static void dumpAsPng(float[][] a, double[][] colormap, double[][] alpha, String filename, boolean interpolatedColors)Dumps the array as a png file, using a specified (optional) colormap and (optional) transparency alpha. The corresponding colors to the values in the array will be linearly interpolated according to the colormap. If the alpha array is given, the corresponding alpha value for the pixel i,j will be set to alpha[i][j], where alpha must be [0,1].- Parameters:
a- The arraycolormap- A 3xm array, of [0,1] values. colormap[0][i] is red, colormap[1][i] green, colormap[2][i] blue.alpha- An array with the same dimensions as a containing transparency values. If null transparency will be 0.
-
array2Image
public static BufferedImage array2Image(float[][] a, double[][] colormap, double[][] alpha, boolean interpolatedColors)
Creates an image from an array using a specified (optional) colormap and (optional) transparency alpha. The corresponding colors to the values in the array will be linearly interpolated according to the colormap. If the alpha array is given, the corresponding alpha value for the pixel i,j will be set to alpha[i][j], where alpha must be [0,1].- Parameters:
a- The arraycolormap- [3][m] values in the range [0,1]. colormap[0][i] is red, colormap[1][i] green, colormap[2][i] blue. Can be null (default; jet-like).alpha- An array with the same dimensions as a containing transparency values. If null transparency will be 0.interpolatedColors- true: interpolate colormap linearly; false: find nearest color; NaN is mapped to first entry in colormap- Returns:
- A BufferedImage object that can be later saved with for example ImageIO.write(image, "PNG", new File("my.png"));
-
-