Example usage for javax.swing ImageIcon getIconHeight

List of usage examples for javax.swing ImageIcon getIconHeight

Introduction

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

Prototype

public int getIconHeight() 

Source Link

Document

Gets the height of the icon.

Usage

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;// w  ww  .  j  a  va  2 s. co m

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

From source file:output.TikzTex.java

/**
 * Use PDF-Latex to parse the .tex file/*from  w w  w.ja  v  a  2 s .  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:sturesy.core.backend.services.ImageService.java

/**
 * Encodes the Image into a Base64-encoded String
 * /*  w  w w  .j a va 2s  .c o m*/
 * @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:sturesy.export.jaxb.adapter.ImageAdapter.java

@Override
public String marshal(ImageIcon v) throws Exception {
    if (v.getIconHeight() != -1 && v.getIconWidth() != -1) {
        ImageService imageservice = new ImageService();
        return imageservice.encodeImage(v);
    } else {/*www.  jav a2 s  .  c  o m*/
        return "";
    }
}

From source file:us.mn.state.dot.tms.client.camera.FTPStream.java

/** Create an image icon from image data */
protected ImageIcon createIcon(byte[] idata) {
    ImageIcon icon = new ImageIcon(idata);
    if (icon.getIconWidth() == size.width && icon.getIconHeight() == size.height)
        return icon;
    Image im = icon.getImage().getScaledInstance(size.width, size.height, Image.SCALE_FAST);
    return new ImageIcon(im);
}

From source file:view.BackgroundImageController.java

public void setGraphBackgroundImage(final VisualizationViewer vv, final ImageIcon background,
        final double xOffset, final double yOffset) {

    removeBackgroundImage(vv);//from w ww.  java 2 s.  c  o  m

    preRender = new VisualizationViewer.Paintable() {
        public void paint(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;
            AffineTransform oldXform = g2d.getTransform();
            AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)
                    .getTransform();
            AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)
                    .getTransform();
            AffineTransform at = new AffineTransform();
            at.concatenate(g2d.getTransform());
            at.concatenate(vat);
            at.concatenate(lat);
            g2d.setTransform(at);
            g.drawImage(background.getImage(), (int) Math.round(-background.getIconWidth() / xOffset),
                    (int) Math.round(-background.getIconHeight() / yOffset), background.getIconWidth(),
                    background.getIconHeight(), vv);
            g2d.setTransform(oldXform);
        }

        public boolean useTransform() {
            return false;
        }
    };

    vv.addPreRenderPaintable(preRender);

    background.getImage().flush();
    Runtime.getRuntime().gc();
}