如何设置从Flash使用Actionscript 3保存的JPG类型的图像截图? [英] How to set JPG type of image screenshot saved from flash using Actionscript 3?

查看:118
本文介绍了如何设置从Flash使用Actionscript 3保存的JPG类型的图像截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,当我想要使用ActionScript 3保存截图整个Flash阶段时,当我点击使用函数 SimpanGbr 的按钮它的作品用名称保存图像 NamaGambar,但没有JPG图像的类型。如何保存图片的类型。我使用这些代码:

  stop(); 
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import com.adobe.images.JPGEncoder;
stage.displayState = StageDisplayState.FULL_SCREEN;

exit.addEventListener(MouseEvent.CLICK,keluar);

函数keluar(event:MouseEvent):void
{
fscommand(quit);


函数SimpanGbr(e:MouseEvent):void {
var qImageData:BitmapData = new BitmapData(800,600);
qImageData.draw(stage);
var qEncoder:JPGEncoder = new JPGEncoder(100);
var qBytes:ByteArray = qEncoder.encode(qImageData);
var qFile:FileReference = new FileReference();
var nama:String =NamaGambar;
qFile.save(qBytes,nama +。jpg);


解决方案

一个href =http://code.google.com/p/as3corelib/ =nofollow>这个库。



将源文件(com文件夹)放到您的Class路径或您的应用程序根目录中。除了JPEGEncoder之外,这个库还包含了很多其他与Hasing,Text,Date等有关的类。
这是我们如何将一个Flash影片的图像保存到本地机器。
$ b 1)从MovieClip或Loader中创建一个BitmapData对象。
$ b 2)使用JPEGEncoder对BitmapData进行编码并形成一个ByteArray使用FileReference.save()将图像下载到用户机器上。

请参阅例如:
创建一个空白的Flash电影,并将其命名为ImageSave.fla。在相同的文件夹中创建ImageSave.as文件,并将下面的代码复制到它。您需要将从as3corelib复制到该文件夹​​的com文件夹。我在舞台上有一个名为save_mc的按钮,它触发了saveImage函数。
$ b $ pre $ package $ {
import flash。 display.MovieClip;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.utils.ByteArray;
导入flash.net.FileReference;
import flash.net.FileFilter;
导入flash.events。*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import com.adobe.images.JPGEncoder;
public class ImageSave extends MovieClip {
private var imgFile:URLRequest;
private var img:MovieClip;
private var imgLoader:Loader;
private var file:FileReference;
public function ImageSave(){
imgFile = new URLRequest(coffee.jpg); //将其更改为图像路径
imgLoader = new Loader();
imgLoader.load(imgFile);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
save_mc.addEventListener(MouseEvent.CLICK,saveImage);

private函数onLoaded(evt:Event):void {
imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onLoaded);
imgLoader.cacheAsBitmap = true;
addChild(imgLoader);

函数saveImage(e:MouseEvent):void {
var myBitmapData:BitmapData = new BitmapData(imgLoader.width,imgLoader.height);
myBitmapData.draw(imgLoader);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
file = new FileReference();
file.browse(new Array(new FileFilter(Images(* .jpg,* .jpeg),* .jpg; *。jpeg)));
file.save(imgByteData,test.jpg);





$ p $为了您的方便,您可以下载此示例的工作副本此处


I have a problem when i wanna save screenshot entire flash stage using ActionScript 3. when i click button that use function SimpanGbr it's works for saving image with name "NamaGambar" but without type of JPG image. How to save image with it's type. I use these codes:

stop();
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import com.adobe.images.JPGEncoder;
stage.displayState = StageDisplayState.FULL_SCREEN;

exit.addEventListener(MouseEvent.CLICK,keluar);

function keluar(event:MouseEvent):void
{
    fscommand("quit");
}

function SimpanGbr(e:MouseEvent):void {
    var qImageData:BitmapData = new BitmapData(800, 600);
    qImageData.draw(stage);
    var qEncoder:JPGEncoder = new JPGEncoder(100);
    var qBytes:ByteArray = qEncoder.encode(qImageData);
    var qFile:FileReference = new FileReference();
    var nama:String="NamaGambar";
    qFile.save(qBytes, nama+".jpg");
}

解决方案

You can do so using this library.

After downloading copy the source files (the com folder) on to your Class path or your application root directory. Apart from the JPEGEncoder, this library is packaged with a lot of other classes related to Hasing, Text, Date etc. This is how we save an image from a flash movie to a local machine.

1) Create a BitmapData object out of the MovieClip or the Loader.

2) Encode the BitmapData using the JPEGEncoder and form a ByteArray.

3) Use FileReference.save() to download the image on to the User machine.

See an example: Create a blank Flash movie and name it as "ImageSave.fla". In the same folder create "ImageSave.as" file and copy the below code in to it. You need the "com" folder copied from the as3corelib to this folder. I have a button on the stage named "save_mc" which triggers the saveImage function.

package {
    import flash.display.MovieClip;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import flash.net.FileFilter;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import com.adobe.images.JPGEncoder;
    public class ImageSave extends MovieClip {
        private var imgFile:URLRequest;
        private var img:MovieClip;
        private var imgLoader:Loader;
        private var file:FileReference;
        public function ImageSave() {
            imgFile = new URLRequest("coffee.jpg"); //change it to your image path
            imgLoader = new Loader();
            imgLoader.load(imgFile);
            imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
            save_mc.addEventListener(MouseEvent.CLICK, saveImage);
        }
        private function onLoaded(evt:Event):void {
            imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaded);
            imgLoader.cacheAsBitmap = true;
            addChild(imgLoader);
        }
        function saveImage(e:MouseEvent):void {
            var myBitmapData:BitmapData = new BitmapData(imgLoader.width, imgLoader.height);
            myBitmapData.draw(imgLoader);
            var jpgEncoder:JPGEncoder = new JPGEncoder(80);
            var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
            file = new FileReference();
            file.browse(new Array(new FileFilter("Images (*.jpg, *.jpeg)", "*.jpg;*.jpeg")));
            file.save(imgByteData, "test.jpg");
        }
    }
}

For your convenience you can download a working copy of this sample here.

这篇关于如何设置从Flash使用Actionscript 3保存的JPG类型的图像截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆