Example usage for com.lowagie.text Image DEFAULT

List of usage examples for com.lowagie.text Image DEFAULT

Introduction

In this page you can find the example usage for com.lowagie.text Image DEFAULT.

Prototype

int DEFAULT

To view the source code for com.lowagie.text Image DEFAULT.

Click Source Link

Document

this is a kind of image alignment.

Usage

From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java

License:Open Source License

private void handleImage(String url, String alt, String borderWidth, String alignment)
        throws DocumentException {
    float marginTopPt = document.topMargin();
    float marginBottomPt = document.bottomMargin();
    float marginLeftPt = document.leftMargin();
    float marginRightPt = document.rightMargin();

    if (url == null)
        return;/*from  w  w  w .  ja v a  2 s.  com*/
    Image img = null;
    String imgSimpleName = "";
    try {
        File imgFile = new File(xhtmlDir, url);
        String imgPath = imgFile.getCanonicalPath();
        imgSimpleName = imgFile.getName();
        img = Image.getInstance(imgPath);
        if (alt == null) {
            alt = imgSimpleName;
        }
        img.setAlt(alt);
    } catch (Exception e) {
        printlnerr("epub2pdf: problem adding image " + imgSimpleName + ": " + e.getMessage());
        return;
    }
    if (borderWidth != null) {
        int border = Integer.parseInt(borderWidth);
        if (border == 0) {
            img.setBorder(Image.NO_BORDER);
        } else {
            img.setBorder(Image.BOX);
            img.setBorderWidth(border);
        }
    }

    if (alignment != null) {
        int align = Image.DEFAULT;
        if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment))
            align = Image.LEFT;
        else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment))
            align = Image.RIGHT;
        else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(alignment))
            align = Image.MIDDLE;
        img.setAlignment(align | Image.TEXTWRAP);
    } else {
        img.setAlignment(Image.MIDDLE);
    }

    Rectangle pageRect = document.getPageSize();
    float verticalMarginTotal = marginTopPt + marginBottomPt;
    float horizontalMarginTotal = marginLeftPt + marginRightPt;

    float imgMaxWidth = pageRect.getWidth() - horizontalMarginTotal - 2;
    float imgMaxHeight = pageRect.getHeight() - verticalMarginTotal - 2;

    float imgOrigWidth = img.getWidth();
    float imgOrigHeight = img.getHeight();

    if (imgOrigHeight > imgMaxHeight || imgOrigWidth > imgMaxWidth) {
        img.scaleToFit(imgMaxWidth, imgMaxHeight);
    }
    boolean addOK = addToDocument(img);
    if (!addOK) {
        System.err.println("** addToDocument(" + img.getUrl() + ") returned false");
    }

}

From source file:com.mainsystem.window.CarRegisterWindow.java

public void loadImage() {
    fc.setDialogTitle("Select file");
    int returnVal = fc.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        byte[] byteImage = imageBuilder.getByteImage(fc.getSelectedFile());
        BufferedImage readyImage = imageBuilder.getBufferedImage(byteImage);

        lblPhoto.setIcon(new ImageIcon(readyImage.getScaledInstance(270, 270, Image.DEFAULT)));

    } else if (returnVal == JFileChooser.CANCEL_OPTION) {
        System.out.println("cancelou");
    }//from   www .jav a2  s.c  o  m
}