----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Paulo Soares" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, July 29, 2003 22:20
Subject: Re: [iText-questions] ArrayIndexOutOfBoundsException when masking
an image
>
> Hi Paulo,
>
> Thanks for the quick response.
> The original image is a JPEG.
>
Very, very bad choice. The compression artifacts will show up if you try to
apply transparency.
> Why is that formula used? On the tutorial, an 8 X 8 mask uses 8 bytes,
> but
> would be 15 bytes using the formula below.
This is integer calculation. The bits are packed but a line is padded to
fill the last byte. No byte spans two lines.
>
> So, assuming that I need 888 bytes for a mask with 6750 pixels, how are
> the
> byte values computed?
>
You'll need (135+7)/8 * 50 = 850 bytes.
Best Regards,
Paulo Soares
> Thanks for your help,
> Chris
>
>
>
>
>
> "Paulo Soares"
>
> <[EMAIL PROTECTED]> To:
> <[EMAIL PROTECTED]>,
> <[EMAIL PROTECTED]>
> Sent by: cc:
>
> [EMAIL PROTECTED] Subject:
> Re: [iText-questions] ArrayIndexOutOfBoundsException when masking an
> image
> eforge.net
>
>
>
>
>
> 07/29/2003 02:25 PM
>
>
>
>
>
>
>
>
>
> The number of bytes must be:
>
> (width+7)/8 * height
>
> What is your original image format before the PlanarImage?
>
> Best Regards,
> Paulo Soares
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, July 29, 2003 19:50
> Subject: [iText-questions] ArrayIndexOutOfBoundsException when masking
> an
> image
>
>
> > Hello,
> >
> > I have an image of a signature with height=50 and width=135 that I
> would
> > like to insert into a PDF. I would like to mask it with the signature
> > itself so that the white background of the image is gone and only the
> > signature remains. I've tried using the code below to do this, but I
> > get
> > the following exception. Am I constructing the mask correctly? I
> > assumed
> > that the number of bytes in the mask should be equal to the ceiling of
> > the
> > number of pixels divided by 8(844 in this case). Is this correct?
> >
> > java.lang.ArrayIndexOutOfBoundsException: 844
> > at com.lowagie.text.pdf.CCITTG4Encoder.nextState(Unknown
> Source)
> > at com.lowagie.text.pdf.CCITTG4Encoder.encodeT6(Unknown
> Source)
> > at com.lowagie.text.pdf.CCITTG4Encoder.compress(Unknown
> Source)
> > at com.lowagie.text.Image.getInstance(Unknown Source)
> > at com.lowagie.text.Image.getInstance(Unknown Source)
> >
> >
> > Here is the code:
> > <snip>
> > PlanarImage planarImage = getPlanarImage(value);
> > byte[] mask = createMask(planarImage);
> > Image maskImage =
> > Image.getInstance(
> > planarImage.getData().getWidth(),
> > planarImage.getData().getHeight(),
> > 1,
> > 1,
> > mask);
> >
> > maskImage.makeMask();
> > maskImage.setInvertMask(true);
> >
> > image.setAbsolutePosition(pageTokenDefinition.getX(),
> > pageTokenDefinition.getY());
> > image.setImageMask(maskImage);
> > pdfTemplate.addImage(image);
> > </snip>
> >
> > private static byte[] createMask(PlanarImage image) {
> > double[][] pixels = imageToBandArray(image, 0);
> > int width = pixels[0].length;
> > int height = pixels.length;
> > byte[] mask = new byte[(int)Math.ceil(width * height / 8.0)];
> > int maskIndex = 0;
> > for (int pixelIndex = 0; pixelIndex < width * height;
> > pixelIndex++) {
> > if (pixels[pixelIndex / width][pixelIndex % width] == 0) {
> > mask[(int)Math.floor(pixelIndex / 8.0)] |= (1 << (7 -
> > pixelIndex % 8));
> > }
> > }
> > return mask;
> > }
> >
> > public static double[][] imageToBandArray(PlanarImage image, int
> > band) {
> > Raster raster = image.getData();
> > int width = raster.getWidth();
> > int height = raster.getHeight();
> > int bands = raster.getNumBands();
> > double[][] bandArray = new double[height][width];
> > for (int n = 0; n < height; n++) {
> > raster.getSamples(0, n, width, 1, band, bandArray[n]);
> > }
> > return bandArray;
> > }
> >
> > Thanks,
> > Chris
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> > Data Reports, E-commerce, Portals, and Forums are available now.
> > Download today and enter to win an XBOX or Visual Studio .NET.
> >
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01
> > /01
> > _______________________________________________
> > iText-questions mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/itext-questions
> >
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01
> /01
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
>
>
>
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions