Hello -
I am having problems using the Java API to write images. When I execute the code below and use HDFView to look at the output image data set it is a faint grey "ghost" of the original image (i.e. it is not a sharp black and white version of the original color image). I would appreciate any pointers to documentation about working with images in Java.
Thanks much!
// create a file
FileFormat ff = FileFormat.getInstance("dset.h5");
ff.create("dset.h5");
ff.createGroup("ImageGroup", null);
ff.close();
ff.open();
// prepare to write the image data set
int gcpl = 0;
Group parent = null;
Group pgroup = (Group) ff.get("ImageGroup");
String name = "2D image";
Datatype dtype = new H5Datatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE,
Datatype.SIGN_NONE);
long[] chunks = null; // no chunking
int gzip = 0; // no compression
int ncomp = 3; // RGB true color image
int interlace = ScalarDS.INTERLACE_PIXEL;
// read the image file
BufferedImage img = null;
try {
img = ImageIO.read(new File("photo116.jpg"));
} catch (IOException e) {
System.out.println("I/O error when reading the image file");
}
int w = img.getWidth();
int h = img.getHeight();
// get the image data in an array
int[] dataBuffInt = img.getRGB(0, 0, w, h, null, 0, w);
long[] dims = { h, w };
long[] maxdims = dims;
// create the image data set
Dataset d = ff.createImage(name, pgroup, dtype, dims, maxdims, chunks, gzip, ncomp, interlace, dataBuffInt);
ff.close();