use of ome.xml.model.enums.handlers.PixelTypeEnumHandler in project bioformats by openmicroscopy.
the class ImageViewer method save.
/**
* Saves the current images to the given destination
* using the current format writer.
*/
public void save(String id) {
if (images == null)
return;
wait(true);
try {
if (omeMeta == null) {
omeMeta = omexmlService.createOMEXMLMetadata();
omeMeta.setImageID(MetadataTools.createLSID("Image", 0), 0);
omeMeta.setPixelsID(MetadataTools.createLSID("Pixels", 0), 0);
omeMeta.setPixelsBigEndian(false, 0);
String order = "XYCZT";
if (in != null)
order = in.getDimensionOrder();
omeMeta.setPixelsDimensionOrder((DimensionOrder) new DimensionOrderEnumHandler().getEnumeration(order), 0);
int type = AWTImageTools.getPixelType(images[0]);
String pixelType = FormatTools.getPixelTypeString(type);
omeMeta.setPixelsType((PixelType) new PixelTypeEnumHandler().getEnumeration(pixelType), 0);
int rgbChannelCount = images[0].getRaster().getNumBands();
int realChannelCount = sizeC / rgbChannelCount;
for (int i = 0; i < realChannelCount; i++) {
omeMeta.setChannelID(MetadataTools.createLSID("Channel", i, 0), 0, i);
omeMeta.setChannelSamplesPerPixel(new PositiveInteger(rgbChannelCount), 0, i);
}
omeMeta.setPixelsSizeX(new PositiveInteger(images[0].getWidth()), 0);
omeMeta.setPixelsSizeY(new PositiveInteger(images[0].getHeight()), 0);
omeMeta.setPixelsSizeC(new PositiveInteger(sizeC), 0);
omeMeta.setPixelsSizeZ(new PositiveInteger(sizeZ), 0);
omeMeta.setPixelsSizeT(new PositiveInteger(sizeT), 0);
}
myWriter.setMetadataRetrieve(omexmlService.asRetrieve(omeMeta));
myWriter.setId(id);
boolean stack = myWriter.canDoStacks();
ProgressMonitor progress = new ProgressMonitor(this, "Saving " + id, null, 0, stack ? images.length : 1);
if (stack) {
// save entire stack
for (int i = 0; i < images.length; i++) {
progress.setProgress(i);
boolean canceled = progress.isCanceled();
myWriter.saveImage(i, images[i]);
if (canceled)
break;
}
progress.setProgress(images.length);
} else {
// save current image only
myWriter.savePlane(0, getImage());
progress.setProgress(1);
}
myWriter.close();
} catch (FormatException exc) {
LOGGER.info("", exc);
} catch (IOException exc) {
LOGGER.info("", exc);
} catch (ServiceException exc) {
LOGGER.info("", exc);
} catch (EnumerationException exc) {
LOGGER.info("", exc);
}
wait(false);
}
Aggregations