下保存自定义影片剪辑作为图像到本地磁盘(DIY发生器) [英] Saving customized movieclip as an image to local disk (diy generator)
问题描述
dropbox.com/s/77euop1luqjreos/FINAL.fla
dropbox.com/s/77euop1luqjreos/FINAL.fla
好吧,我便放弃了这个了。我想不出任何办法挽救由用户创建的图像。它很难解释,但请看看我工作的FLA文件。基本上,它是一个DIY的发电机。唯一缺少的是一个保存功能。香港专业教育学院读的FileReference但它总是在一个文档类。我的code是时间轴。请帮助我真的很坚持。
Ok i just gave up with this already. I cant think of any way to save the image created by a user. Its hard to explain but please check out the fla file of my work. Basically its a diy generator. The only thing missing is a save function. Ive read filereference but its always in a document class. My code is in the timeline. Please help I'm really stuck.
编辑:我有一个下载按钮即现在的工作!但它不仅节省了影片剪辑的一小部分: Imgur
edit: I got a download button that is working now!! But it only saves a small part of the movieclip: Imgur
推荐答案
为了创建图像,您需要访问的影片剪辑对象的像素数据。这些数据可以通过渲染的MovieClip 到的BitmapData STRONG>对象,并使用这些数据,您可以编写自己的EN codeR将其转换为任何图像格式,你可以得到倒是像。写这样的EN codeR不是一个简单的任务,需要图像格式算法的理解,也可以使用pre-写库。您也可以下载 PNGEn codeR 和 JPGEn codeR ,这是的的as3corelib ,一个开源项目库。
In order to create images, you need to access the pixel data of the MovieClip object. The data can be obtained by rendering a MovieClip into a BitmapData object and using this data, you can write your own encoder to convert it to any image format you’d like. Writing such encoder is not a trivial task and requires understanding of the image format algorithm, or you can use pre-written libraries. You can download the PNGEncoder and JPGEncoder , which is part of as3corelib, an open source project library.
使用的 JPGEn codeR ,我们可以把的DisplayObject 到的ByteArray ,适合保存到文件中。如果使用的是 JPGEn codeR ,它会是这样的:
Using the JPGEncoder, we can convert DisplayObject into ByteArray, suitable for saving into file. If using the JPGEncoder, it’ll look like this:
import com.adobe.images.JPGEncoder;
var jpgEncoder:JPGEncoder = new JPGEncoder(quality);
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
通过在 PNGEn codeR ,它会是这样的:
With the PNGEncoder, it’ll look like this:
import com.adobe.images.PNGEncoder;
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
保存到用户的硬盘
使用的的FileReference .save()函数,我们可以提示用户将文件保存与以下调用。
Using the FileReference.save() function, we can prompt the user to save the file with the following call.
var fileReference:FileReference=new FileReference();
//in case of JPGEncoder
fileReference.save(byteArray, ".jpg");
通过这两个结合起来,这里有一个例子,如何使用:
With the two combined, here’s an example how to use:
//remember to import
import flash.net.FileReference;
import com.adobe.images.JPGEncoder; //or import com.adobe.images.PNGEncoder;
import flash.utils.ByteArray;
import flash.display.BitmapData;
//where mc_canvas will be your MovieClip instance name
var bitmapData:BitmapData = new BitmapData(mc_canvas.width, mc_canvas.height);
bitmapData.draw(mc_canvas);
var jpgEncoder:JPGEncoder = new JPGEncoder(quality_slider.value);
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
//if you want to use PNGEncoder
//var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
var fileReference:FileReference = new FileReference();
fileReference.save(byteArray, ".jpg");
这篇关于下保存自定义影片剪辑作为图像到本地磁盘(DIY发生器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!