import java.io.*; import loci.common.ByteArrayHandle; import loci.common.Location; import loci.common.services.DependencyException; import loci.common.services.ServiceException; import loci.common.services.ServiceFactory; import loci.formats.*; import loci.formats.meta.IMetadata; import loci.formats.services.OMEXMLService; import loci.formats.in.NDPIReader; import loci.formats.gui.BufferedImageReader; import java.awt.image.BufferedImage; public class testplain { public static void main(String[] args) { try { String fn = "test3-DAPI 2 (387) .ndpi"; // read in entire file System.out.println("Reading file into memory from disk..."); File inputFile = new File(fn); int fileSize = (int) inputFile.length(); DataInputStream in = new DataInputStream(new FileInputStream(inputFile)); byte[] inBytes = new byte[fileSize]; in.readFully(inBytes); System.out.println(fileSize + " bytes read."); in.close(); String fileName = inputFile.getName(); int dot = fileName.lastIndexOf("."); String suffix = dot < 0 ? "" : fileName.substring(dot); // map input id string to input byte array final String inId = "inBytes" + suffix; Location.mapFile(inId, new ByteArrayHandle(inBytes)); NDPIReader reader = new NDPIReader(); reader.setFlattenedResolutions(true); reader.setId(inId); System.out.println("size reader: "+reader.getSizeX()+" x" +reader.getSizeY()); // works byte[] bytes = reader.openBytes(0, 0, 0, 100, 100); // IndexOutOfBoundsException !!! reader.close(); } catch (Exception e) { System.err.println("Exception: " + e); e.printStackTrace(); } } }