Interface ImageDataAtSizeProvider

All Superinterfaces:
ImageDataProvider

public interface ImageDataAtSizeProvider extends ImageDataProvider
An extension of the ImageDataProvider that is capable of providing image data at a specified size instead of or in addition to a specified zoom. This requires an implementation of the getImageData(int, int) method for providing image data at a specified size. Optionally, the getDefaultSize() method can be overwritten such that the image data can also be retrieved via a zoom that uses the default size as reference for the 100% version. This serves two use cases:
  1. The image data source is size independent, such that the provider can specify at what size the image data is to be provided. As an example, an SVG image source may be defined at arbitrary size and the implementation of this provider can define at which default size the image is to be used at 100% zoom. To achieve this, the getImageData(int, int) has to be implemented for the retrieval of image data at a given size and getDefaultSize() has to be overwritten to define the default size at 100% zoom.
  2. An image created with this data provider is to be drawn at a custom size (and not a specific zoom). Such a drawing can be performed via GC.drawImage(Image, int, int, int, int). For this case, getDefaultSize() does not need to be overwritten, as the zoom-based version of the image data is not of interest.
Since:
3.132
  • Method Summary

    Modifier and Type
    Method
    Description
    default Point
    Returns the default size of the image data returned by this provider.
    default ImageData
    getImageData(int zoom)
    Returns the image data for the given zoom level.
    getImageData(int width, int height)
    Returns the ImageData for the given width and height.
  • Method Details

    • getImageData

      default ImageData getImageData(int zoom)
      Description copied from interface: ImageDataProvider
      Returns the image data for the given zoom level.
      • If no image is available for a particular zoom level, this method should return null. For zoom == 100, returning null is not allowed, and SWT will throw an exception.
      • Implementations are expected to return ImageData that is linearly scaled with respect to the zoom level. For example, if getImageData(100) returns an image of width w and height h, then getImageData(200) must return an ImageData of width 2 * w and height 2 * h, if a non-null result is returned.
      Specified by:
      getImageData in interface ImageDataProvider
      Parameters:
      zoom - The zoom level in % of the standard resolution (which is 1 physical monitor pixel == 1 SWT logical point). Typically 100, 150, or 200.
      Returns:
      the linearly scaled image data for the given zoom level, or null if zoom != 100 and no image is available for the given zoom level.
    • getDefaultSize

      default Point getDefaultSize()
      Returns the default size of the image data returned by this provider. It conforms to the size of the data that is returned when calling getImageData(int) with a zoom value of 100. This method can also return (-1, -1), in which case getImageData(int) will return dummy data of size (1, 1). This reduces potential overheads for the use case in which image data is only retrieved size-based via getImageData(int, int).
      Returns:
      the default size of the data returned by this provider for 100% zoom
    • getImageData

      ImageData getImageData(int width, int height)
      Returns the ImageData for the given width and height.

      Implementation notes:

      • Returning null is not permitted. If null is returned, SWT will throw an exception when loading the image.
      • The returned ImageData must match the requested width and height exactly. Implementations should ensure proper resizing and scaling of the image based on the height and width requested
      Parameters:
      width - the desired width of the ImageData to be returned
      height - the desired height of the ImageData to be returned
      Returns:
      the ImageData that exactly matches the requested width and height