Example usage for javax.swing ImageIcon getImage

List of usage examples for javax.swing ImageIcon getImage

Introduction

In this page you can find the example usage for javax.swing ImageIcon getImage.

Prototype

@Transient
public Image getImage() 

Source Link

Document

Returns this icon's Image.

Usage

From source file:org.wings.SImageIcon.java

protected static String determineMimeType(ImageIcon imageIcon) {
    String mimeType = extractMimeTypeFromPath(imageIcon.getDescription());
    if (mimeType != null)
        return mimeType;
    PixelGrabber pg = new PixelGrabber(imageIcon.getImage(), 0, 0, 1, 1, false);
    try {/*w ww  .  j  a  va2s.c  o m*/
        pg.grabPixels();
    } catch (InterruptedException e) {
        log.warn("interrupted waiting for pixels!");
    }

    mimeType = "image/";
    if (!(pg.getColorModel() instanceof IndexColorModel))
        mimeType += ImageExternalizer.FORMAT_PNG;
    else
        mimeType += ImageExternalizer.FORMAT_GIF;

    return mimeType;
}

From source file:org.xulux.swing.util.SwingUtils.java

/**
 * Returns the image based on the resource.
 * The resource should be available to the classloader,
 * otherwize it will fail loading.//from w w w  . j ava2s. co m
 * It will use the ImageInterface when jimi is supported
 *
 * @param resource - the resource from the classpath
 * @param object - the object to get the classLoader from.
 *                  At this time it cannot be null
 * @return the Image retrieved
 */
public static Image getImage(String resource, Object object) {
    if (resource == null || object == null) {
        return null;
    }
    ImageCache cache = null;
    if (object instanceof Widget) {
        Widget w = (Widget) object;
        if (w.getPart() != null) {
            cache = w.getPart().getImageCache();
        }
    }
    Image retValue = null;
    if (cache != null) {
        retValue = cache.getImage(resource);
    }
    if (retValue == null) {
        if (imageLoader != null) {
            URL imageURL = object.getClass().getClassLoader().getResource(resource);
            retValue = imageLoader.getImage(imageURL);
        } else {
            ImageIcon icon = getIcon(resource, object);
            if (icon != null) {
                retValue = icon.getImage();
            }
        }
        if (retValue != null && cache != null) {
            cache.addImage(resource, retValue);
        }
    }

    return retValue;
}

From source file:org.yccheok.jstock.gui.NewBrokingFirmJDialog.java

private void loadImage(File file) {
    ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath());

    if (imageIcon.getIconWidth() <= 0 || imageIcon.getIconHeight() <= 0)
        return;//from  w w w .  j  a va 2 s.c o  m

    this.setLogo(imageIcon.getImage());
}

From source file:output.TikzTex.java

/**
 * Use PDF-Latex to parse the .tex file/*  w w  w  . j a va 2s.c o m*/
 * @param file the source File containing the Data
 * @throws IOException
 */
public void genPdf(File file) throws IOException {
    ProcessBuilder pb = new ProcessBuilder("pdflatex", "-shell-escape", file.getAbsolutePath());
    File directory = new File(outputDir);
    pb.directory(directory);

    Process p;
    try {
        p = pb.start();
        // We need to parse the Error and the Output generated by pdflatex
        StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
        StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
        errorGobbler.start();
        outputGobbler.start();
        // Wait until its done
        int exitVal = p.waitFor();

        // Spawn a Frame with the Image
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        String imgPath = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4) + ".png";
        ImageIcon icon = new ImageIcon(imgPath);
        // resize
        Image img = icon.getImage();
        double ratio = (double) icon.getIconWidth() / icon.getIconHeight();
        Image newimg = img.getScaledInstance((int) (Math.round(600 * ratio)), 600, java.awt.Image.SCALE_SMOOTH);
        icon = new ImageIcon(newimg);
        JLabel imgLabel = new JLabel(icon);
        JScrollPane scrollPanel = new JScrollPane(imgLabel);

        frame.getContentPane().add(scrollPanel);
        frame.setSize(1280, 720);
        frame.setVisible(true);
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void init() {
    String fileName = String.format("/%s/sync-256px.png", getClass().getPackage().getName().replace(".", "/"));
    ImageIcon imageIcon = new ImageIcon(getClass().getResource(fileName));
    setIconImage(imageIcon.getImage());

    mOptions.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        String key = evt.getKey();
        if (key.equalsIgnoreCase(ClientOptions.KEY_MENU_ICONS)) {
            loadClientOption(ClientOptionsEvent.MENU_ICONS);
        } else if (key.equalsIgnoreCase(ClientOptions.KEY_FORCE_LOOK_AND_FEEL)
                || key.equalsIgnoreCase(ClientOptions.KEY_LOOK_AND_FEEL)) {
            loadClientOption(ClientOptionsEvent.LOOK_AND_FEEL);
        } else if (key.equalsIgnoreCase(ClientOptions.KEY_ICON_THEME)) {
            mAllActions.stream().forEach((jotaAction) -> {
                jotaAction.updateIcon();
            });//  w w  w  .ja v a  2  s .c  o m
        }
    });

    mActionManager = new ActionManager();
    mActionManager.initActions();

    mTabHolder = new TabHolder();
    add(mTabHolder);
    mTabHolder.initActions();
    mManager.addConnectionListeners(this);

    loadClientOption(ClientOptionsEvent.LOOK_AND_FEEL);
    loadClientOption(ClientOptionsEvent.MENU_ICONS);

    updateWindowTitle();

    try {
        SwingHelper.frameStateRestore(this, 800, 600);
    } catch (BackingStoreException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:se.trixon.mapollage.ui.MainFrame.java

private void init() {
    String fileName = String.format("/%s/icon-1024px.png", getClass().getPackage().getName().replace(".", "/"));
    ImageIcon imageIcon = new ImageIcon(getClass().getResource(fileName));
    setIconImage(imageIcon.getImage());

    configPanel.addStatusPanel(mStatusPanel);
    mProgressBar = mStatusPanel.getProgressBar();

    mModel = (DefaultComboBoxModel) profileComboBox.getModel();

    loadProfiles();//from w  ww.  j  a v a  2 s.  c  om
    populateProfiles(null, 0);
    initListeners();

    mLogErrPanel = mStatusPanel.getLogErrPanel();
    mLogOutPanel = mStatusPanel.getLogOutPanel();

    mLogOutPanel.println(mBundleUI.getString("welcome_1"));
    mLogOutPanel.println(Mapollage.getHelp());
    mLogOutPanel.scrollToTop();

    setRunningState(false);
    SwingUtilities.invokeLater(() -> {
        configPanel.setEnabled(!mProfiles.isEmpty());
    });
}

From source file:se.trixon.pacoma.ui.MainFrame.java

private void init() {
    String fileName = String.format("/%s/pacoma-icon.png", getClass().getPackage().getName().replace(".", "/"));
    ImageIcon imageIcon = new ImageIcon(getClass().getResource(fileName));
    setIconImage(imageIcon.getImage());

    initListeners();// w w  w . j  a va  2 s . c o m
}

From source file:sturesy.core.backend.services.ImageService.java

/**
 * Encodes the Image into a Base64-encoded String
 * /*from  w  w w  .ja v  a 2 s.  c om*/
 * @return Base64-encoded String
 */
public String encodeImage(ImageIcon _questionImage) {
    if (_questionImage == null)
        return "";

    BufferedImage bi = new BufferedImage(_questionImage.getIconWidth(), _questionImage.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(_questionImage.getImage(), 0, 0, null);
    g2.dispose();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        ImageIO.write(bi, "png", baos);

        baos.flush();
    } catch (IOException e) {
        Log.error("error converting image to bytearray", e);
    } finally {
        try {
            baos.close();
        } catch (IOException e) {
        }
    }

    return Base64.encodeBase64String(baos.toByteArray());
}

From source file:ueg.watchdog.util.ImageUtils.java

/**
 * Method to resize and visualize the user selected image within the image
 * label/*from w  ww .  ja  va 2 s. c o  m*/
 *
 * @param imagePath Path to the image
 * @param width     expected weight
 * @param height    expected height
 * @return {@link ImageIcon}
 */
public static ImageIcon resizeImage(String imagePath, int width, int height) {
    ImageIcon ic = new ImageIcon(imagePath);
    Image img = ic.getImage();
    Image newImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    return new ImageIcon(newImage);
}

From source file:ui_server.frmScreenShut.java

private void imageImpiliment(JLabel img) {
    ImageIcon IIC = (ImageIcon) img.getIcon();
    Image image = IIC.getImage();
    BufferedImage buffered = (BufferedImage) image;
    try {/* w ww .  j a  v a2 s .  co  m*/
        File outputfile = new File("saved.png");
        ImageIO.write(buffered, "png", outputfile);
    } catch (IOException e) {
    }
}