title: Read pixel from a big jp2 image without loading the whole image into memory
body: <p>I'm trying to read parts from a big image in java. My image size is more than 700 MB. I have used this code which normally reads pixels without loading the whole image into memory: </p>
  
  <pre><code>Rectangle sourceRegion = new Rectangle(0, 0, 512, 512); // The region you want to extract
  
  ImageInputStream stream = ImageIO.createImageInputStream( new File("/home/dhoha/Downloads/BreastCancer.jp2")); // File or input stream
  final Iterator&lt;ImageReader&gt; readers = ImageIO.getImageReaders(stream);
  
  if (readers.hasNext()) {
  ImageReader reader = (ImageReader)readers.next();
  
  reader.setInput(stream, true);
  
  ImageReadParam param = reader.getDefaultReadParam();
  param.setSourceRegion(sourceRegion); // Set region
  
  BufferedImage image = reader.read(0, param); // Will read only the region specified
  </code></pre>
  
  <p>However, I got the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Dimensions (width=95168 height=154832) are too large
      at java.awt.image.SampleModel.&lt;init&gt;(SampleModel.java:130)
      at java.awt.image.ComponentSampleModel.&lt;init&gt;(ComponentSampleModel.java:146)
      at java.awt.image.PixelInterleavedSampleModel.&lt;init&gt;(PixelInterleavedSampleModel.java:87)
      at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createSampleModel(J2KRenderedImageCodecLib.java:741)
      at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createOriginalSampleModel(J2KRenderedImageCodecLib.java:729)
      at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.&lt;init&gt;(J2KRenderedImageCodecLib.java:261)
      at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:364)
      at testJai2.test3.main(test3.java:21)
  </code></pre>
  
  <p>Any help please to read parts from this big image?</p>