Link to home
Start Free TrialLog in
Avatar of smilewithYash
smilewithYashFlag for India

asked on

convert Sprite and its children in to bitmap for print

Hello All,

I am new to flex. so please excuse me if i ask some silly things.  But I am making an drawing application where i required my sprite to be in print.
In application there is two mode in printing
1. Full Mode
2> Multiple mode
 In full mode i have to print sprite (that contain all the drawing object in it)only one time.But in multiple mode i have to make multiple times in desired size on single page.From here my problem start.

Right now i am using alivePDF for converting my sprite in to pdf format and then i send that converted pdf to php page.I have to use only PHP as it is client requirement.

For Multiple Printing I use SNAPSHOT in flex to capture my sprite and its Contain t but then when i create its pdf its distort or not show images in exact mean.
I used matrix scale function to resize my bitmap data which i get from SNAPShot.

Is there any way to do such thing.??
Avatar of dgofman
dgofman
Flag of United States of America image

Also you can merge images when you are using multiple SNAPSHOT option

The following example creates two BitmapData objects. Both are 100 x 80 pixels in size. The first is filled with green and the second is filled with red. The code calls the merge() method, merging the second BitmapData pixels into the first BitmapData object, but only on a specified rectangular area:

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bmd1:BitmapData = new BitmapData(100, 80, true, 0xFF00FF00);
var bmd2:BitmapData = new BitmapData(100, 80, true, 0xFFFF0000);
var rect:Rectangle = new Rectangle(0, 0, 20, 20);
var pt:Point = new Point(20, 20);
var mult:uint = 0x80; // 50%
bmd1.merge(bmd2, rect, pt, mult, mult, mult, mult);

var bm1:Bitmap = new Bitmap(bmd1);
addChild(bm1);
var bm2:Bitmap = new Bitmap(bmd2);
addChild(bm2);
bm2.x = 110;
Avatar of smilewithYash

ASKER

thanks for reply dgofman

ya actually i tried this thing.i add with for loop and also for specifying margins between sprite.But when i print them they didn't appear as they look on screen.

for explaining things: Like i am drawing a rectangle element with boarder around it and then when i go for multi print on some boarder comes right and for some it vanished from left side or from rightside.

i searched over net ..............there i find that snapshot draw bitmap in low dpi ...so i was thinking that may be the problem.??

PLease can you attach your sample I will review and fix it
Ya Sure....i can let you see wat happening in my application.

plz look for demo http://demo.b24solutions.com/flex/adobeflex/planetLabel.html.....there you will find print section on single label mode.then you can see what i want to say....
Plz delete  ".....there"  from above url

original one is

http://demo.b24solutions.com/flex/adobeflex/planetLabel.html

plz login with a@a.com and 1234.
Can you give me steps for reporoducing your problem?
Did you try to use http://alivepdf.bytearray.org/ its very good quality of SNAPHOTS images
actaully i am using this currently..

ok here are steps

login with the user name and password ..........
 1>select first option that is used default templates.
     click continue
2> select page size rectangle 11X8.5
    click continue
3> select single mode.

4> draw anything so you can chk

now click on print.........select print preciew then you will see the problem

hoping for quick reply
So, you want a single image print (one page) am I right\?
Ya as you see there is difference between images .....i don't know why this hapeening.

if(templateHeight == templateWidth)
                  {
                        if(HOL)
                        {
                              for(var j:Number = 0;j< WCount ; j++)
                              {
                                    for(var i:Number = 0;i< HCount ; i++)
                                    {
                                          backgroundLayer.graphics.beginFill(shapeColor,1);
                                          backgroundLayer.graphics.moveTo(tempMarginH,tempMarginV);
                                          backgroundLayer.graphics.drawRoundRect(backX+tempMarginH,backY+tempMarginV,recV,recH,actualRadius);
                                          addElementToo(tempMarginH,tempMarginV);
                                          backgroundLayer.graphics.endFill();
                                          tempMarginH = marginH + tempMarginH + recV;      
                                    }
                                    tempMarginV = marginV + tempMarginV + recH;
                                    tempMarginH = marginH;
                              }
                        }
}

here backgroundLayer work as a final view of design (when single label mode converted to multiple mode)
here is the code for addelementtoo()

var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(layerContainer);
                              var matrix:Matrix = new Matrix();
                              matrix.transformPoint(new Point(bitmapData.width/2,bitmapData.height/2));
                              matrix.scale(1/WCount,1/HCount);
                              var bitmapDat:BitmapData = ImageSnapshot.captureBitmapData(layerContainer,matrix);
                              var bitmap:Bitmap = new Bitmap(bitmapDat,PixelSnapping.ALWAYS,true);                        
                              backgroundLayer.addChild(bitmap);

now this final backgroundLayer is send to alivepdf where it is converted as pdf and shown for print.

plz help......i have no idea what i was doing wrong here
anyOne Plz Help me out......Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for help....this really helps but i have to use bitmap api as my application have masking on labels and i have to prit only label no additional things.

this is the client requirement.......earlier i was trying snapshot .......but now i am using bitmap draw method it gives me pleasing result not accurate though........working on this .............