I'm developing a java application : it will display images from omero by using the BufferedImage class. The format of images can be jpeg, tiff, png..
I have developed the following code based on an example given on the Omero web site :
- Code: Select all
RawPixelsStorePrx rawPixelsStorePrx = serviceFactoryPrx.createRawPixelsStore();
rawPixelsStorePrx.setPixelsId(pixelsId, false);
for (int z = 0; z < sizeZ; z++) {
for (int t = 0; t < sizeT; t++) {
for (int c = 0; c < sizeC; c++) {
byte[] imageInBytes = rawPixelsStorePrx.getPlane(z, c, t);
// convert byte array back to BufferedImage
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageInBytes);
BufferedImage bufferedImage;
try {
bufferedImage = ImageIO.read(inputStream);
} catch (IOException ex) {
// Can not read the image (image not found or not supported format)
bufferedImage = null;
}
ImageBean imageBean = new ImageBean("omero:iid=" + imageId, bufferedImage);
imageBeans.add(imageBean);
}
}
}
rawPixelsStorePrx.close();
In this case, the returned bufferedImage is always null (I have tested with jpeg, tiff and png).
I have tried another code based on the Omero web site :
- Code: Select all
RenderingEnginePrx proxy = serviceFactoryPrx.createRenderingEngine();
proxy.lookupPixels(pixelsId);
if (!(proxy.lookupRenderingDef(pixelsId))) {
proxy.resetDefaultSettings(true);
proxy.lookupRenderingDef(pixelsId);
}
proxy.load();
// Now can interact with the rendering engine.
proxy.setActive(0, Boolean.valueOf(false));
// to render the image uncompressed
PlaneDef pDef = new PlaneDef();
pDef.z = 0;
pDef.t = 0;
pDef.slice = omero.romio.XY.value;
//render the data uncompressed.
int[] uncompressed = proxy.renderAsPackedInt(pDef);
byte[] compressed = proxy.renderCompressed(pDef);
//Create a buffered image
ByteArrayInputStream stream = new ByteArrayInputStream(compressed);
BufferedImage bufferedImage;
try {
bufferedImage = ImageIO.read(stream);
} catch (IOException ex) {
// Can not read the image (image not found or not supported format)
bufferedImage = null;
}
ImageBean imageBean = new ImageBean("omero:iid=" + imageId, bufferedImage);
imageBeans.add(imageBean);
// Close
proxy.close();
The returned bufferedImage is not null but the displayed image is not correct (black image for tiff, strange colors for png and jpeg).
I think I not correctly use the BufferedImage class (I'm new with the image display in java applications). Could you please help me ?
Thank you in advance
Céline