views:

228

answers:

1

How to copy something as a pastable bitmap in flash?

So I have simple mxml project - empty page with a panel on it.

I want to be able to select some region on my panel and copy it somehow as bitmap pastable to photoshop, word and other programms.

How to do such thing? (libs, articles etc)

Edit - It may be not possible in FP10 but in FP 10.1 you can have it=) See BETA ActionScript 3.0 Reference for the Adobe Flash Platform 10.1 Not in the best way ever but any way what's so ever

  • first use ClipboardFormats - HTML_FORMAT (which IS supported by FP10)
  • Create some template HTML
  • Embed your BitmapData to it (Use Encoders)
  • Now you can paste it in to Word and some other programms
+1  A: 

You can't do that with Flex/Flash, but you can take a snapshot and save that to the filesystem and import that image to photoshop etc. Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

    <mx:Script>
        <![CDATA[
            import mx.graphics.codec.PNGEncoder;
            import flash.display.BitmapData;

            protected function saveAsPNG(target:Sprite, path:String):void
            {
                var bitmapData:BitmapData = new BitmapData(target.width, target.height);
                bitmapData.draw(target);

                var image:PNGEncoder = new PNGEncoder();
                var byteArray:ByteArray = image.encode(bitmapData);

                var file:FileReference = new FileReference();
                file.save(byteArray, path);
            }
        ]]>
    </mx:Script>

    <mx:Panel width="100%" height="100%">
        <mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
            <mx:Panel width="50%" height="50%"/>
            <mx:Panel width="50%" height="50%"/>
        </mx:HBox>
    </mx:Panel>

    <mx:Button label="Save As.." click="saveAsPNG(this, 'MyImage.png')"/>

</mx:Application>

If you use AIR, you can save Bitmaps to the Clipboard. Check out this advanced AIR Clipboard Application.

You also might be able to do the following:

(not sure if that's possible)

It looks like you can't even copy images to the clipboard in javascript. If you're on a Mac, you can use this: Command+Ctrl+Shift+4.

Hope that helps, Lance

viatropos
why we can not to save Bitmaps to the Clipboard in FP?
Blender
I think it's to prevent security breaches. The Clipboard class is AIR Only (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/desktop/Clipboard.html) also :/. http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes.html
viatropos