title: Writing to TIFF: illegal byte order
body: <p>I have been trying to draw a huge image file from lots of smaller Images in BufferedImage-format (using one big BufferedImage takes more memory than I have) and am now trying to do this via the replacePixels-Function of the ImageWriter-class.</p>
  
  <p>However; i do get a puzzling error which even extensive Googleing could not fix, so I hope someone here can tell me what I'm doing wrong:</p>
  
  <pre><code>javax.imageio.IIOException: Illegal byte order
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.locateIFD(TIFFImageWriter.java:2813)
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.readIFD(TIFFImageWriter.java:3076)
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.canReplacePixels(TIFFImageWriter.java:3099)
  at drawingTiles.WorldMapMaker$1.writeImg(WorldMapMaker.java:90)
  at drawingTiles.WorldMapMaker$1.run(WorldMapMaker.java:148)
  at java.lang.Thread.run(Unknown Source)
  javax.imageio.IIOException: Illegal byte order
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.locateIFD(TIFFImageWriter.java:2813)
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.readIFD(TIFFImageWriter.java:3076)
  at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.prepareReplacePixels(TIFFImageWriter.java:3141)
  at drawingTiles.WorldMapMaker$1.writeImg(WorldMapMaker.java:104)
  at drawingTiles.WorldMapMaker$1.run(WorldMapMaker.java:148)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I do know what a byte order is, I do not know how a byte-order can be illegal. This is the function I am using:</p>
  
  <pre><code>public void writeImg (String path, int startx, int starty, BufferedImage image){
              File output = new File(path);
              ImageOutputStream ios = null;
              try {
                  ios = ImageIO.createImageOutputStream(output);
              } catch (IOException e){
                  e.printStackTrace();
              }
  
              Iterator&lt;ImageWriter&gt; iter = ImageIO.getImageWritersByFormatName("TIF");
              ImageWriter writer = (ImageWriter)iter.next();
              writer.setOutput(ios);
  
              TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
              writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  
              try{
                  if(writer.canReplacePixels(0)){ // LINE 90
                      System.out.println("True");
                  }else{
                      System.out.println("False");
                  }
              }catch (IOException e) {
                  e.printStackTrace();
              }
  
              Point destinationOffset = new Point(startx,starty);
              writeParam.setDestinationOffset(destinationOffset);
  
              try {
                  writer.prepareReplacePixels(0, new Rectangle(0, 0, image.getWidth(), image.getHeight())); // LINE 104
                  writer.replacePixels(image, writeParam);
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  </code></pre>