Example usage for com.lowagie.text Image setTransparency

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

Introduction

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

Prototype

public void setTransparency(int transparency[]) 

Source Link

Document

Sets the transparency values

Usage

From source file:jm.web.Addons.java

License:GNU General Public License

public static Image setMarcaAgua(String logo, int ancho, int alto) {
    try {/* w w  w .  j  a  v a2  s  .c  o m*/
        Image imagelogo = Image.getInstance(logo);
        imagelogo.setTransparency(new int[] { 255, 255 });
        imagelogo.setRotationDegrees(57);
        imagelogo.scaleAbsolute(ancho, alto);
        imagelogo.setAbsolutePosition(0, 30);
        return imagelogo;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:questions.images.MakingImageTransparent.java

public static void main(String args[]) {
    try {/*from  ww  w.j  a  v a  2  s  .  com*/
        Rectangle rect;
        // GIF Image
        Image gif = Image.getInstance(GIF);
        gif.setAbsolutePosition(0, 0);
        gif.setTransparency(new int[] { 0x5B, 0x5D });
        rect = new Rectangle(gif.getScaledWidth(), gif.getScaledHeight());
        rect.setBackgroundColor(Color.YELLOW);

        Document document = new Document(rect);
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        document.add(gif);

        // JPEG Image
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(JPG);
        Image jpg = Image.getInstance(awtImage, null, true);
        jpg.setTransparency(new int[] { 0xF0, 0xFF });
        jpg.setAbsolutePosition(0, 0);
        rect = new Rectangle(jpg.getScaledWidth(), jpg.getScaledHeight());
        rect.setBackgroundColor(Color.YELLOW);

        document.setPageSize(rect);
        document.newPage();
        document.add(jpg);
        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:questions.images.OverlappingImages.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.POSTCARD);
    try {/*from   ww  w  . j a v a 2 s. c o  m*/
        // step 2:
        // we create a writer
        PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document
        Image img1 = Image.getInstance(RESOURCE1);
        img1.scaleToFit(PageSize.POSTCARD.getWidth(), 10000);
        img1.setAbsolutePosition(0, 0);
        document.add(img1);
        Image img2 = Image.getInstance(RESOURCE2);
        img2.setTransparency(new int[] { 0x00, 0x10 });
        img2.setAbsolutePosition(PageSize.POSTCARD.getWidth() - img2.getScaledWidth(),
                PageSize.POSTCARD.getHeight() - img2.getScaledHeight());
        document.add(img2);
        Image img3 = Image.getInstance(RESOURCE3);
        img3.setTransparency(new int[] { 0xF0, 0xFF });
        img3.setAbsolutePosition((PageSize.POSTCARD.getWidth() - img3.getScaledWidth()) / 2,
                (PageSize.POSTCARD.getHeight() - img3.getScaledHeight()) / 2);
        document.add(img3);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();

}