Ejemplo n.º 1
0
  private Asset createAssetFromIcon(ImageIcon icon) {
    if (icon == null) return null;

    // Make sure there is a buffered image for it
    Image image = icon.getImage();
    if (!(image instanceof BufferedImage)) {
      image =
          new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT);
      Graphics2D g = ((BufferedImage) image).createGraphics();
      icon.paintIcon(null, g, 0, 0);
    }
    // Create the asset
    Asset asset = null;
    try {
      asset = new Asset(name, ImageUtil.imageToBytes((BufferedImage) image));
      if (!AssetManager.hasAsset(asset)) AssetManager.putAsset(asset);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return asset;
  }