?
Solved

convert Sprite and its children in to bitmap for print

Posted on 2011-05-12
14
Medium Priority
?
1,030 Views
Last Modified: 2013-11-11
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.??
0
Comment
Question by:smilewithYash
  • 7
  • 7
14 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 35752318
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35752327
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;
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35752726
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.??

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:dgofman
ID: 35755544
PLease can you attach your sample I will review and fix it
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35774645
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....
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35774916
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.
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35775125
Can you give me steps for reporoducing your problem?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35775144
Did you try to use http://alivepdf.bytearray.org/ its very good quality of SNAPHOTS images
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35775217
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
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35775496
So, you want a single image print (one page) am I right\?
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35775687
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
0
 
LVL 1

Author Comment

by:smilewithYash
ID: 35783042
anyOne Plz Help me out......Thanks in advance
0
 
LVL 29

Accepted Solution

by:
dgofman earned 1000 total points
ID: 35783174
I am not sure you need to use Bitmap data API if you are using AlivePDF

Let me give you example how scale working using AlivePDF APIs

I have images 600x400 I would like to add 4 on the sigle page by 300x200

<?xml version="1.0" encoding="utf-8"?>
<s:Application  xmlns:fx="http://ns.adobe.com/mxml/2009"
				xmlns:s="library://ns.adobe.com/flex/spark"
				xmlns:mx="library://ns.adobe.com/flex/mx">
	
	<fx:Script>
		<![CDATA[
			import org.alivepdf.display.Display;
			import org.alivepdf.display.PageMode;
			import org.alivepdf.layout.Layout;
			import org.alivepdf.layout.Orientation;
			import org.alivepdf.layout.Size;
			import org.alivepdf.layout.Unit;
			import org.alivepdf.pdf.PDF;
			import org.alivepdf.saving.Method;
			
			
			[Bindable] private var rows:Array;
			
			public function printPdf():void{
				var w:uint = 300;
				var h:uint = 200;
				var myPDFEncoder:PDF = new PDF(Orientation.PORTRAIT, Unit.POINT, Size.LETTER);
				myPDFEncoder.addPage();
				myPDFEncoder.addImage(container, 0, 0, w, h);
				myPDFEncoder.addImage(container, w, 0, w, h);
				myPDFEncoder.addImage(container, 0, h, w, h);
				myPDFEncoder.addImage(container, w, h, w, h);
				myPDFEncoder.setDisplayMode(Display.REAL, Layout.SINGLE_PAGE, PageMode.USE_NONE, 1);
				var output:* = myPDFEncoder.save(Method.LOCAL);
				var aFile:FileReference = new FileReference();
				aFile.save(output,"myPDF.pdf");
				
			}
		]]>
	</fx:Script>
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<mx:HBox width="100%" horizontalAlign="center" direction="horizontal" paddingLeft="10" paddingRight="10" >
		<mx:Button label="Print PDF" click="printPdf()"/> 
	</mx:HBox>
	
	<mx:VBox width="100%" height="100%">
		<mx:HBox id="container" width="600" height="400">
			<mx:RichTextEditor title="Title" text="Here I am testing custom font" width="100%" height="100%"/>
		</mx:HBox>
	</mx:VBox>
</s:Application> 

Open in new window

0
 
LVL 1

Author Closing Comment

by:smilewithYash
ID: 35783215
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 .............
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question