Class HiDPISupport


  • public final class HiDPISupport
    extends Object
    Helper class for HiDPI support. Gives access to the class BaseMultiResolutionImage via reflection, in case it is on classpath. This is to be expected for Java 9, but not for Java 8 runtime.
    Since:
    12722
    • Method Detail

      • getMultiResolutionImage

        public static Image getMultiResolutionImage​(Image base,
                                                    ImageResource ir,
                                                    ImageResizeMode resizeMode)
        Create a multi-resolution image from a base image and an ImageResource.

        Will only return multi-resolution image, if HiDPI-mode is detected. Then the image stack will consist of the base image and one that fits the HiDPI scale of the main display.

        Parameters:
        base - the base image
        ir - a corresponding image resource
        resizeMode - how to size/resize the image
        Returns:
        multi-resolution image if necessary and possible, the base image otherwise
      • getMultiResolutionImage

        public static Image getMultiResolutionImage​(List<Image> imgs)
        Create a multi-resolution image from a list of images.
        Parameters:
        imgs - the images, supposedly the same image at different resolutions, must not be empty
        Returns:
        corresponding multi-resolution image, if possible, the first image in the list otherwise
      • getBaseImage

        public static Image getBaseImage​(Image img)
        Wrapper for the method java.awt.image.BaseMultiResolutionImage#getBaseImage().

        Will return the argument img unchanged, if it is not a multi-resolution image.

        Parameters:
        img - the image
        Returns:
        if img is a java.awt.image.BaseMultiResolutionImage, then the base image, otherwise the image itself
      • getResolutionVariants

        public static List<ImagegetResolutionVariants​(Image img)
        Wrapper for the method java.awt.image.MultiResolutionImage#getResolutionVariants().

        Will return the argument as a singleton list, in case it is not a multi-resolution image.

        Parameters:
        img - the image
        Returns:
        if img is a java.awt.image.BaseMultiResolutionImage, then the result of the method #getResolutionVariants(), otherwise the image itself as a singleton list
      • getResolutionVariant

        public static Image getResolutionVariant​(Image img,
                                                 double destImageWidth,
                                                 double destImageHeight)
        Wrapper for method java.awt.image.MultiResolutionImage#getResolutionVariant(double destImageWidth, double destImageHeight).

        Will return the argument, in case it is not a multi-resolution image.

        Parameters:
        img - the image
        destImageWidth - the width of the destination image
        destImageHeight - the height of the destination image
        Returns:
        if img is a java.awt.image.BaseMultiResolutionImage, then the result of the method #getResolutionVariant(destImageWidth, destImageHeight), otherwise the image itself
      • getHiDPIScale

        public static double getHiDPIScale()
        Detect the GUI scale for HiDPI mode.

        This method may not work as expected for a multi-monitor setup. It will only take the default screen device into account.

        Returns:
        the GUI scale for HiDPI mode, a value of 1.0 means standard mode.
      • processMRImage

        public static Image processMRImage​(Image img,
                                           UnaryOperator<Image> processor)
        Perform an operation on multi-resolution images. When input image is not multi-resolution, it will simply apply the processor once. Otherwise, the processor will be called for each resolution variant and the resulting images assembled to become the output multi-resolution image.
        Parameters:
        img - input image, possibly multi-resolution
        processor - processor taking a plain image as input and returning a single plain image as output
        Returns:
        multi-resolution image assembled from the output of calls to processor for each resolution variant
      • processMRImages

        public static Image processMRImages​(List<Image> imgs,
                                            Function<List<Image>,​Image> processor)
        Perform an operation on multi-resolution images. When input images are not multi-resolution, it will simply apply the processor once. Otherwise, the processor will be called for each resolution variant and the resulting images assembled to become the output multi-resolution image.
        Parameters:
        imgs - input images, possibly multi-resolution
        processor - processor taking a list of plain images as input and returning a single plain image as output
        Returns:
        multi-resolution image assembled from the output of calls to processor for each resolution variant