Cannot load JPEG with java created by Samsung phone : <p>I am having trouble loading a JPEG image shot by a Samsung Galaxy S7 edge with javafx (image available at <a href="https://www.dropbox.com/s/w6lvdnqwcgw321s/20171122_140732.jpg?dl=0" rel="noreferrer">https://www.dropbox.com/s/w6lvdnqwcgw321s/20171122_140732.jpg?dl=0</a>). I am using the Image class to load the image.</p>

<pre><code>import java.io.FileInputStream;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class JPEGProblem extends Application {

   public static void main(String[] args) {
      launch(args);
   }

   @Override
   public void start(Stage window) throws Exception {
      Image img = new Image(new FileInputStream("/path/to/image.jpg"));
      if (img.getException() != null)
         throw img.getException();

      ImageView imgView = new ImageView(img);
      window.setScene(new Scene(new Pane(imgView)));
      window.show();
   }

}
</code></pre>

<p>The constructor call, which tries to load the image prints the following error message on the error stream:</p>

<blockquote>
  <p>Feb 04, 2018 11:48:23 PM
  com.sun.javafx.tk.quantum.PrismImageLoader2$PrismLoadListener imageLoadWarning
  WARNING: Invalid SOS parameters for sequential JPEG</p>
</blockquote>

<p>The exception, that I get from the image object is an IOException with the message:</p>

<blockquote>
  <p>Unsupported marker type 0x65</p>
</blockquote>

<p>I've done some research and it turns out, that it is a known issue with panorama images shot by a samsung phone. As pointed out in this thread: <a href="https://forums.adobe.com/thread/2131432" rel="noreferrer">https://forums.adobe.com/thread/2131432</a>, some of the 0xFF bytes, that indicate the following byte to be meta information rather than actual data are not escaped by adding a following 0x00 byte after the 0xFF.<br>
However I tried to write code that manipulates the image data in order to add the missing 0x00 bytes, but that turned out to be far more complicated, than expected and I don't want to write my own JPEG parser/loader.<br>
There are some programs, that can display those invalid JPEG images e.g. Microsoft Fotos or Paint. It seems like they tolerate these invalid images, treating those spurious markers as content data.<br>
Is there any way to load these invalid images with java, without dealing with the single bytes myself?</p>
