简体   繁体   中英

Can I open a browser window to view an image created by a flex 3 application?

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

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.

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;

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:

Flex: Render an unrealized UIComponent to BitmapData?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM