简体   繁体   English

如何使用ActionScript3 / PHP从swf导出图像?

[英]How to export image from swf with ActionScript3/PHP?

i have another piece for more advanced guys than me ;) 我还有比我更高级的家伙;)

I am developing a simple flash application to create your own coat of arms. 我正在开发一个简单的Flash应用程序,以创建自己的徽章。 When finished creating, it would be nice to save it as an image to a client's computer or to a database, i am not sure yet. 创建完成后,最好将其另存为客户端计算机或数据库中的图像,我不确定。 The problem is making the image from swf content - i mean not the whole content, just a part of it, where the COA is. 问题是从swf内容制作图像-我的意思不是COA所在的全部内容,只是一部分。 I have found some eamples on the web using some image encoders and PHP, but i cant't understand how it works. 我在网络上使用一些图像编码器和PHP找到了一些示例,但是我不明白它是如何工作的。 Could anybody be so kind to explain me the basic principles of this? 有人会这样向我解释这一基本原理吗? I want to make it as simple as possible. 我想使其尽可能简单。

First, draw the image (Sprite or MovieClip, etc) into a BitmapData: 首先,将图像(Sprite或MovieClip等)绘制到BitmapData中:

var b: BitmapData = new BitmapData(640, 480, false, 0xffffffff); 
b.draw(mcToBeSaved);

Then, use eg as3corelib to encode the BitmapData into PNG or JPG files. 然后,使用例如as3corelib将BitmapData编码为PNG或JPG文件。

var ba: ByteArray = PNGEncoder.encode(b);

Then, for Flash 10, you can immediately get the user to save the image to a file, using FileReference's save method. 然后,对于Flash 10,您可以立即使用户使用FileReference的save方法将图像保存到文件中。

This seems to be a popular question lately. 最近,这似乎是一个受欢迎的问题。 So I don't completely reiterate all that information, instructions for saving the image data, once you've obtained that as BitmapData, are here: 因此,在您获得BitmapData的信息后,我不会完全重申所有这些信息,有关保存图像数据的说明位于:

How can I send a ByteArray (from Flash) and some form data to php? 如何将ByteArray(从Flash)和一些表单数据发送到php?

But, first, to get the image data, you'll need to pull it out of whatever MovieClip/Sprite, whatever you have it in. To do this, you simply do: 但是,首先,要获取图像数据,您需要将其从任何MovieClip / Sprite中提取出来,无论将其放入其中。要执行此操作,只需执行以下操作:

var myBitmapData:BitmapData = new BitmapData(desiredWidth, desiredHeight, isTransparent, backgroundColor); var myBitmapData:BitmapData =新的BitmapData(desiredWidth,desiredHeight,isTransparent,backgroundColor); myBitmapData.draw(mcToBeSavedToImage); myBitmapData.draw(mcToBeSavedToImage);

Where mcToBeSavedToImage is the movieclip you want to turn into an image. 其中mcToBeSavedToImage是要转换为图像的动画片段。 The BitmapData reference is here, if you need it - it has other examples: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html 如果需要,可以在这里找到BitmapData参考-其他示例: http : //livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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