Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8267563

Support loading images from inline data-URIs

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx17
    • javafx
    • None
    • behavioral
    • minimal
    • This adds support for the data URL protocol, so an Image that is constructed with "data" URL will decode the image instead of setting the "error" property.
    • File or wire format
    • JDK

      Summary

      Add support for loading images from RFC 2397 "data" URIs.

      Problem

      JavaFX can currently only load images from files on disk and memory streams, which makes it hard to embed small images into code and CSS files.

      Solution

      Data URIs are a widely accepted solution for embedding small images. The data URI scheme can be supported in JavaFX by detecting and parsing the scheme in ImageStorage and other places.

      Specification

      Change the class documentation of javafx.scene.image.Image as follows:

      -  * <p>
      -  * All URLs supported by {@link URL} can be passed to the constructor.
      -  * If the passed string is not a valid URL, but a path instead, the Image is
      -  * searched on the classpath in that case.
      -  * </p>
      +  * <p>If a URL string is passed to a constructor, it be any of the following:
      +  * <ol>
      +  *     <li>the name of a resource that can be resolved by the context
      +  *         {@link ClassLoader} for this thread
      +  *     <li>a file path that can be resolved by {@link java.io.File}
      +  *     <li>a URL that can be resolved by {@link java.net.URL} and for
      +  *         which a protocol handler exists
      +  * </ol>
      +  *
      +  * <p>The RFC 2397 "data" scheme for URLs is supported in addition to
      +  * the protocol handlers that are registered for the application.
      +  * If a URL uses the "data" scheme, the data must be base64-encoded
      +  * and the MIME type must either be empty or a subtype of the
      +  * {@code image} type.

      Change the documentation of the Image(String url) constructor as follows:

      -  * @param url the string representing the URL to use in fetching the pixel
      -  *      data
      +  * @param url a resource path, file path, or URL

      Change the documentation of the Image(String url, boolean backgroundLoading) constructor as follows:

      -  * Constructs a new {@code Image} with the specified parameters.
      +  * Constructs an {@code Image} with content loaded from the specified URL
      +  * using the specified parameters.
      
      -  * @param url the string representing the URL to use in fetching the pixel
      -  *      data
      +  * @param url a resource path, file path, or URL

      Change the documentation of the Image(String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth) constructor as follows:

      -  * Constructs a new {@code Image} with the specified parameters.
      +  * Constructs an {@code Image} with content loaded from the specified URL
      +  * using the specified parameters.
      
      -  * @param url the string representing the URL to use in fetching the pixel
      -  *      data
      +  * @param url a resource path, file path, or URL

      Change the documentation of the Image(String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth, boolean backgroundLoading) constructor as follows:

      -  * Constructs a new {@code Image} with the specified parameters.
      +  * Constructs an {@code Image} with content loaded from the specified URL
      +  * using the specified parameters.
         *
      -  * The <i>url</i> without scheme is threated as relative to classpath,
      -  * url with scheme is treated accordingly to the scheme using
      -  * {@link URL#openStream()}
      -  *
      -  * @param url the string representing the URL to use in fetching the pixel
      -  *      data
      +  * @param url a resource path, file path, or URL

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: