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.
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:
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.
> >
> >
> >
> >
> >
> >
> >
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:
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.
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.
if you pass "false" as second argument of getBitmapdataInstance it used the old way, otherwise it converts the image into png first
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;