image background

113 views
Skip to first unread message

Paul Hastings

unread,
Jan 11, 2011, 1:23:33 PM1/11/11
to purepdf...@googlegroups.com
first off let me say how nice it is to find an iText port like this. great job.

i have an issue with the background of captured images. i'm grabbing an image of
a graph via ImageSnapshot & inserting into a PDF. the insert works fine but the
graph image background is black in the PDF (it's white in the flex 4 app). if i
set the ImageElement background color to white or light gray, the whole image
becomes white or light gray.

code snippet:

var elevProfileImg:ImageElement=
ImageElement.getBitmapDataInstance(ImageSnapshot.captureBitmapData(elevationProfile));
elevProfileImg.alignment=ImageElement.LEFT;
elevProfileImg.scaleToFit(pageAreaWidth,elevProfileImg.height);
elevProfileImg.borderWidth=5;
elevProfileImg.borderSides=RectangleElement.LEFT | RectangleElement.TOP |
RectangleElement.RIGHT | RectangleElement.BOTTOM;
elevProfileImg.borderColor=RGBColor.GRAY;
elevProfileImg.backgroundColor=RGBColor.LIGHT_GRAY; // covers whole image
// same for white background

any ideas?

thanks.

Alessandro Crugnola

unread,
Jan 11, 2011, 1:27:29 PM1/11/11
to purepdf...@googlegroups.com
Not sure about the problem but I remember I had similar problems when testing images..
I also never used ImageSnapshot.
Anyway, i will make some test here and i'll let you know.

Paul Hastings

unread,
Jan 12, 2011, 1:33:13 AM1/12/11
to purepdf...@googlegroups.com
On 1/12/2011 1:27 AM, Alessandro Crugnola wrote:
> Not sure about the problem but I remember I had similar problems when testing images..
> I also never used ImageSnapshot.
> Anyway, i will make some test here and i'll let you know.

thanks.

if it helps to see, the generated PDF is here:

http://dl.dropbox.com/u/130830/ridePlanner.pdf


and the original graph (screen capture) from the flex app can be seen here:

http://dl.dropbox.com/u/130830/elevProfile.jpg

Alessandro Crugnola

unread,
Jan 12, 2011, 8:09:32 AM1/12/11
to krzyszt...@gmail.com, purepdf...@googlegroups.com
Good news is that I currently found the error with transparent PNG, it was a wreid bug in the way I was using the zlib inflater..
Now I have to check the bitmapdata problem.
At least, if I can't fix the bitmapdata issue asap, you can always convert the bitmapdata into png and add that to the document.

On 11/gen/2011, at 21.43, krzyszt...@gmail.com wrote:

> This problem is available when you use image with transparent background (like in PNG)
> I tryed capture text field with transparency and i see this same effect like you wrote.
>
>
>
> W dniu Alessandro Crugnola <alessandr...@gmail.com> napisał(a):


> > Not sure about the problem but I remember I had similar problems when testing images..
> >
> > I also never used ImageSnapshot.
> >
> > Anyway, i will make some test here and i'll let you know.
> >
> >
> >
> >
> >
> >
> >

Alessandro Crugnola

unread,
Jan 12, 2011, 9:49:58 AM1/12/11
to purepdf...@googlegroups.com
I've currently uploaded a new version of purePDF.
Actually the changes are:
* fixed the png transparency issue
* changed the ImagElement.getBitmapDataInstance( bitmap: BitmapData, has_transparency: boolean = true ) method ( first argument is a bitmapdata, second argument is a boolean indicating if to assume the image has transparency )

Previous version of getBitmapDataInstance was converting the bitmap into a tiff image, without alpha informations, so that's why the bitmapdata had a black boackground. unfortunately the tiff decoder used actually does not support extra_samples of tiff so in case the image has_transparecy i will convert it into PNG.

This is just a temporary fix, I think i can find a better solution, but I don't have time right now to work on it. I will chech it asap I will have some more spare time.


On 11/gen/2011, at 19.23, Paul Hastings wrote:

Paul Hastings

unread,
Jan 12, 2011, 11:35:07 AM1/12/11
to purepdf...@googlegroups.com
On 1/12/2011 9:49 PM, Alessandro Crugnola wrote:
> I've currently uploaded a new version of purePDF. Actually the changes are: *
> fixed the png transparency issue * changed the
> ImagElement.getBitmapDataInstance( bitmap: BitmapData, has_transparency:
> boolean = true ) method ( first argument is a bitmapdata, second argument is
> a boolean indicating if to assume the image has transparency )

great. looks good.

> Previous version of getBitmapDataInstance was converting the bitmap into a
> tiff image, without alpha informations, so that's why the bitmapdata had a
> black boackground. unfortunately the tiff decoder used actually does not
> support extra_samples of tiff so in case the image has_transparecy i will
> convert it into PNG.

ok.

as a workaround gspir...@gmail.com suggested (off-list) that i use BitmapData
instead. that worked fine (set the transparency option).


many thanks.

Alessandro Crugnola

unread,
Jan 12, 2011, 3:53:56 PM1/12/11
to purepdf...@googlegroups.com
how?

loogie

unread,
Jan 12, 2011, 5:41:30 PM1/12/11
to purepdf-discuss
sorry i thought replying in my email posted here since it creates a
reply in my inbox if i post here.. ah well..

I just said that I've been using the BitmapData.Draw() function to get
the bitmap data instead of using ImageSnapshot... you simply make a
new BitmapData of the size of the control you wish to snapshot and
then use the draw function to create the bitmap...

var bitmapData:BitmapData = new BitmapData(0,0,obj.width, obj.height);
bitmapData.draw(obj);

it takes matrices and such as well... its just a function built into
the BitmapData class.

On Jan 12, 3:53 pm, Alessandro Crugnola
<alessandro.crugn...@gmail.com> wrote:
> On 12/gen/2011, at 17.35, Paul Hastings wrote:
>
>
>
> > On 1/12/2011 9:49 PM, Alessandro Crugnola wrote:
> >> I've currently uploaded a new version of purePDF. Actually the changes are: *
> >> fixed the png transparency issue * changed the
> >> ImagElement.getBitmapDataInstance( bitmap: BitmapData, has_transparency:
> >> boolean = true ) method ( first argument is a bitmapdata, second argument is
> >> a boolean indicating if to assume the image has transparency )
>
> > great. looks good.
>
> >> Previous version of getBitmapDataInstance was converting the bitmap into a
> >> tiff image, without alpha informations, so that's why the bitmapdata had a
> >> black boackground. unfortunately the tiff decoder used actually does not
> >> support extra_samples of tiff so in case the image has_transparecy i will
> >> convert it into PNG.
>
> > ok.
>
> > as a workaround gspirido...@gmail.com suggested (off-list) that i use BitmapData instead. that worked fine (set the transparency option).
>
> how?

loogie

unread,
Jan 12, 2011, 5:44:38 PM1/12/11
to purepdf-discuss
sorry that first line is just

var bitmapData:BitmapData = new BitmapData(obj.width, obj.height);

Alessandro Crugnola

unread,
Jan 12, 2011, 5:47:14 PM1/12/11
to purepdf...@googlegroups.com
yes i know about the bitmapdata.draw.
but in that way the result image in the pdf had still the black background

Paul Hastings

unread,
Jan 12, 2011, 6:46:38 PM1/12/11
to purepdf...@googlegroups.com
On 1/13/2011 3:53 AM, Alessandro Crugnola wrote:
> how?

var bmp:BitmapData=new
BitmapData(elevationProfile.width,elevationProfile.height,true);
bmp.draw(elevationProfile);
var elevProfileImg:ImageElement=ImageElement.getBitmapDataInstance(bmp);

http://dl.dropbox.com/u/130830/ridePlanner.pdf

unfortunately it seems those latest changes broke both ImageSnapshot and
BitmapData methods. the app throws a time out error for both methods. i'll poke
around later today.

Alessandro Crugnola

unread,
Jan 12, 2011, 6:51:13 PM1/12/11
to purepdf...@googlegroups.com
> unfortunately it seems those latest changes broke both ImageSnapshot and BitmapData methods. the app throws a time out error for both methods. i'll poke around later today.

if you pass "false" as second argument of getBitmapdataInstance it used the old way, otherwise it converts the image into png first

Alessandro Crugnola

unread,
Jan 13, 2011, 7:58:15 AM1/13/11
to purepdf...@googlegroups.com
I think I found a better solution for BitmapData images.
using this method to obtain a new ImageElement, the returned ImageElement will have a transparency, crated using the alpha informations from the BitmapData.
You can find an example usage here (http://bit.ly/fGUkwF and the running demo at http://bit.ly/dOT2ob ):


protected function createTransparentImageElement( bitmap: BitmapData ): ImageElement
{
var output: ByteArray = new ByteArray();
var transparency: ByteArray = new ByteArray();
var input: ByteArray = bitmap.getPixels( bitmap.rect );
input.position = 0;

while( input.bytesAvailable ){
const pixel: uint = input.readInt();

// write the RGB informations
output.writeByte( (pixel >> 16) & 0xff );
output.writeByte( (pixel >> 8) & 0xff );
output.writeByte( (pixel >> 0) & 0xff );

// write the alpha informations
transparency.writeByte( (pixel >> 24) & 0xff );
}

output.position = 0;
transparency.position = 0;

var mask: ImageElement = ImageElement.getRawInstance( bitmap.width, bitmap.height, 1, 8, transparency, null );
var image: ImageElement = ImageElement.getRawInstance( bitmap.width, bitmap.height, 3, 8, output, null );

if( bitmap.transparent )
{
mask.makeMask();
image.imageMask = mask;
}
return image;

Krzysztof Wylot

unread,
Jan 13, 2011, 11:48:38 AM1/13/11
to purepdf...@googlegroups.com
PNG  working, fine :), Great Thanks


2011/1/13 Alessandro Crugnola <alessandr...@gmail.com>



--
Pozdrawiam

Krzysiek

Alessandro Crugnola

unread,
Jan 13, 2011, 11:53:14 AM1/13/11
to purepdf...@googlegroups.com
I know, but I think this way it's much faster
Reply all
Reply to author
Forward
0 new messages