public static Image getImage(final String imagePath, Component component) {
    URL imageUrl = null;
    URL imageUrl2x = null;
    for (String path : SEARCH_PATHS) {
      // Try to find a 2x scaled version of the image.
      imageUrl = BinDiff.class.getResource(path + imagePath);
      imageUrl2x =
          BinDiff.class.getResource(
              path
                  + BinDiffFileUtils.removeFileExtension(imagePath)
                  + "@2."
                  + FileUtils.getFileExtension(new File(imagePath)));
      if (imageUrl != null) {
        break;
      }
    }
    if (imageUrl == null) {
      logger.atWarning().log("Image resource not found: \"%s\"", imagePath);
      return null;
    }

    final Toolkit toolkit =
        component != null ? component.getToolkit() : Toolkit.getDefaultToolkit();
    final Image image = toolkit.getImage(imageUrl);
    final Image image2x = imageUrl2x != null ? toolkit.getImage(imageUrl2x) : null;

    // Ensure all resolution variants are loaded. While Swing also uses a MediaTracker to track
    // image load state, it does so inconsistently, sometimes leading to "Invalid Image variant"
    // errors during paint. Waiting for these images should be fast, as they are part of the JAR.
    final MediaTracker mt = new MediaTracker(component != null ? component : new JComponent() {});
    mt.addImage(image, 0);
    if (image2x != null) {
      mt.addImage(image2x, 1);
    }
    try {
      mt.waitForAll();
    } catch (final InterruptedException e) {
      logger.atWarning().withCause(e).log(
          "Interrupted while loading image resource: \"%s\"", imagePath);
    }

    if (image2x == null) {
      return image;
    }
    return new BaseMultiResolutionImage(image, image2x);
  }
Utility class to load images from BinDiff package resources.
java/ui/src/main/java/com/google/security/zynamics/bindiff/utils/ResourceUtils.java