DomingoSL
DomingoSL

Reputation: 15504

Save a picture from a MovieClip in FLASH possible? (simple image editor in flash)

I need a very simple(*) image editor made in Flash so the users of my web page can edit pictures and then save them to my server. I'm beginning this project trying to save to a jpg or png the content of a movie clip, but I didn't find any information on Google. Can you give suggestions of how to begin? And if you know some opensource projects like this one, please share it here. Thanks for any help!

(*) very simple means, resize, crop, add text and overlap other images.

Upvotes: 1

Views: 1724

Answers (4)

Myk
Myk

Reputation: 6215

The step it sounds like you're missing is bitmapData.draw(myDisplayObject).

So for instance, you have a MovieClip that's playing, or a video stream from a webcam, or whatever - any display object.

You can say:

var bmd:BitmapData = new BitmapData(320, 240);
bmd.draw(MyMovieClip); // bmd now contains the image you're trying to save.

// then you use something like PNGEncoder.encode. As mentioned above, that comes from Mike Chambers - https://github.com/mikechambers/as3corelib
var byteArray:ByteArray = PNGEncoder.encode(bmd); // now you have a binary stream holding your image

From there, the saving mechanism is up to you. You can pass that ByteArray to a .php script, for instance, that's going to save it to a server and return the URL. You can use FileReference.save - any of the options outlined in the other answers.

The key is making sure that you have a ByteArray built from a BitmapData object containing your image, encoded into a .png or .jpg format.

I hope that helps!

Upvotes: 3

www0z0k
www0z0k

Reputation: 4434

you can call system file saving dialog by FileReference.save(data:ByteArray/*generated by as3corelib image encoding class*/, name:String)

Upvotes: 0

Lars Blåsjö
Lars Blåsjö

Reputation: 6127

The as3corelib has JPG and PNG encoders that you can use to convert a DisplayObject to image data (via BitmapData).

https://github.com/mikechambers/as3corelib

You can probably find some examples or tutorials on how to combine that with saving the images to your server.

Upvotes: 1

zzzzBov
zzzzBov

Reputation: 179246

Flash can't directly access a user's computer as they're in different security sandboxes. If you're using Adobe Air there is support for some file-io stuff, but I'm not sure how that works.

The workaround for allowing people to save their images is to send the image data to a server script (PHP, Perl, Python, whatever...) and have the script present an image to the user. If you use the header application/octet-stream, most user agents will ask the user if they'd like to save the file (there are other work arounds as well).

Pixlr is a good example of that sort of interaction.

Upvotes: 3

Related Questions