tags:

views:

327

answers:

3

I have a flex 3 application that creates an Image from a canvas which the user draws on. I use the ImageSnapshot class to create the image

var imageSnap:ImageSnapshot=ImageSnapshot.captureImage(myCanvas);
   var imageByteArray:ByteArray=imageSnap.data as ByteArray;

I want the user to be able to print or save the image. I can use the following code to print the image but flex does not provide good control over printing across multiple pages

var printJob:FlexPrintJob=new FlexPrintJob();
       printJob.start();
       printJob.addObject(myCanvas, FlexPrintJobScaleType.SHOW_ALL);

I would like to display the image in a browser window so that the user could print it using the built in browser functionality or right click on the image and save it. Can this be done without requesting server side code to do it? I know that flash player 10 and flex 4 allow you to save files locally but for now I am stuck with player 9 and flex 3

A: 

I don't believe you can do this, as it would violate the sandbox. For example, if this worked, it means you could put arbitrary code (analogous to an image) on the user's machine without their consent or knowledge.

Vinay Sajip
It wouldn't be without their consent if they can view the image in a new browser window and then choose what to do with it
Phil C
True, but my point is that if the mechanism existed then a malicious developer could do this.
Vinay Sajip
A: 

I'm not sure if this will work, but try this:

Show a link to the image (file://path/to/image/img.ext) and set window.htmlLoader.navigateInSystemBrowser = true;

trex279
A: 

You can still use the new features of FileReference (the save() and load() methods) in Flex 3 as long as the application is running in Flash Player 10. But if you are definitely stuck with Flash Player 9 then you will need to push the image up to the server first. If you are looking for a good way to push that data up to the server, please reference my solution in this question:

http://stackoverflow.com/questions/1313857/flex-render-an-unrealized-uicomponent-to-bitmapdata/1331930#1331930

cliff.meyers
We did something similar to save reports in .csv format for another project. I was trying to avoid the round trip to the server in this case
Phil C
Do you have a sample php file which echos the image back to the client for saving?
Phil C