Friday, 15 May 2015

How to make an image a qualified mask candidate in itext? -


I want to mask an image, for example, . AGGG itext in the other emblem using B.jpg , and first of all, I try to mask imageB directly and I have received the document Exception: This image can not be an image mask, so I B.jpg is a rawimage these are my codes:

  RandomAccessFile rf = new RandomAccessFile ("B.jpg", "rw"); Int size = (int) rf.length (); Byte iJgata [] = new byte [size]; Rf.readFully (data); Rf.close (); Image mask = Image.getInstance ("BJG"); Int w = (int) Math.ceil (mask .getWidth ()); Int h = (int) Math.ceil (mask .getHeight ()); Mask = Image.getInstance (w, h, 1,1, data); Mask.makemask ();  

I have received byte [] data from B.jpg and try to rebuild BJG >, But it does not work, I can not get the right image, so how can I make the image an image mask? Is there any other way to cover it with any other image? Image but mask fast can be quite complex, not only rectangular or circle which you can draw with ContentByte.

Please take a look at the example. In this example, I took two normal JPG files and one for the other As a mask I did an experiment, which resulted in a scary PDF:

Image Details Here Enter

To achieve this, I need to convert a colorful JPEG into a black and white image:

  IFF (String Dest) throws IOException, DocumentException {document document = new document (pagesize 4. a rotate ()); PdfWriter Author = PdfWriter.getInstance (Document, New FileOutputStream (Dest)); Document.open (); Image Image = Image.getInstance (IMAGE); Image mask = MacBlack & WightPang (MASK); Mask.makeMask (); Image.setImageMask (mask); Image.scaleAbsolute (PageSize.A4.rotate ()); Image.setAbsolutePosition (0, 0); Document.add (image); Document.close (); } Public static image throws IWException (String image), DocumentException {BufferedImage bi = ImageIOread} (New file (image)); Buffer image newb = new buffard image (bygetwidth), bygatehit (), buffard image .tp_USHORERERA;); NewBi.getGraphics (). DrawImage (BI, 0, 0, empty); BytereonOperputTemperatureBaos = New BytereOutStream (); ImageIO.write (newBi, "png", baoos); Return Image.getInstance (baos.toByteArray ()); }  

As you can see, we have transformed the Berlin 2013.jpg into a black and white image and we color it in 2013.jpg as a mask for the image Have used.

/ div>

No comments:

Post a Comment