ActionScript 2.0中屏幕捕获屏幕、ActionScript

2023-09-09 21:29:30 作者:老衲法号乱来

我做了一个闪光灯的场景,我想打一个按钮,当pressed,节省了现场,或者它为JPG的一部分。 我找到了一个不错的教程(的http://www.screentime.com/software/flash-projector/docs/AS3-mApp-captureScreenToJP.htm),但是当我将code:

I made a flash scene, and I want to make a button that, when pressed, saves the scene, or a part of it as JPG. I found a nice tutorial (http://www.screentime.com/software/flash-projector/docs/AS3-mApp-captureScreenToJP.htm), but when I insert the code:

mApplication.captureScreenToJPG(文件名:screen.jpg [X:100] [,Y:540] [,宽度:100] [,身高:400]):虚空

mApplication.captureScreenToJPG(fileName:screen.jpg[, x:100][, y:540][, width:100][, height:400]) : Void

...它没有做任何事情。

...it doesn't do anything.

推荐答案

要开始,我有两点意见:

To start, I have two remarks :

在你的问题中提到的code不是一个标准的ActionScript code,你应该有一个特殊的应用程序来获取code工作。在你的情况,这是ScreentimeMedia的mProjector,这将SWF转换成一个桌面应用程序,可以做很多事情,一个标准的SWF文件不能做到像进行截图并保存为图像文件。

The code mentioned in your question is not a standard ActionScript code, you should have a special application to get that code working. In your case, It's the mProjector of ScreentimeMedia, which will convert the SWF to a desktop application that can do many things that a standard SWf file can't do like taking a screen shot and saving it as image file.

您应该知道,ActionScript 2的不能写入文件到硬盘,除非共享课程对象。所以,要想让你的场景的快照,你必须发送图像到外部脚本,它可以将其保存为一个文件,例如像一个PHP脚本。

You should know that ActionScript 2 can not write files to hard disk, unless shared object of course. So, to get a snapshot of your scene, you have to send image to an external "script" which can save it as a file, like a PHP script for example.

要做到这一点,拿这个例子中,在那里我有3个按钮(btn_stage,btn_mc,btn_zone)和1个影片剪辑(movie_clip),在这里,我假设你的SWF是一个Web应用程序,它可以执行PHP脚本中:

To do that, take this example, where I have 3 buttons (btn_stage, btn_mc, btn_zone) and 1 MovieClip (movie_clip), and here I am assuming that your swf is within a web application which can execute a PHP script :

的ActionScript 2 code:

var bmp_data:BitmapData;

btn_stage.onPress = function() {    
    // here we will take a snapshot of our scene
    // if you want take all the scene (with empty and blank areas), we should use Stage.width and Stage.height : 
    // bmp_data = new BitmapData(Stage.width, Stage.height);
    // if you want only take areas with object and shapes, ..., you can use _root dimensions :
    bmp_data = new BitmapData(_root._width, root._height);
    bmp_data.draw(_root);

    take_snapshot(bmp_data);    
} 
btn_mc.onPress = function() {
    // to take a snapshot only of a MovieClip in our Stage : 
    bmp_data = new BitmapData(movie_clip._width, movie_clip._height); 
    bmp_data.draw(movie_clip);

    take_snapshot(bmp_data);
} 
btn_zone.onPress = function() {
    // if we want to take a snapshot of a specific zone (area) in our Stage
    // we start by drawing all our Stage into a BitmapData object
    var bmp_data_temp:BitmapData = new BitmapData(Stage.width, Stage.height);
        bmp_data_temp.draw(_root);

    // then we copy only the specific area from it, here we will take a square of 100px starting from (100, 100) to (200, 200)
    bmp_data = new BitmapData(100, 100);
    bmp_data.copyPixels(bmp_data_temp, new Rectangle(100, 100, 100, 100), new Point(0, 0));

    take_snapshot(bmp_data);
}

function take_snapshot(bmp_data:BitmapData) {

    var pixels:Array = [];
    var w:Number = bmp_data.width;
    var h:Number = bmp_data.height;

    // get all pixels of our image (BitmapData)
    for (var i = 0; i<= w; i++) {
        for (var j = 0; j <= h; j++) {
            var tmp = bmp_data.getPixel(i, j).toString(16);
            pixels.push(tmp);
        }
    }
    var php_return:LoadVars = new LoadVars();
    var image_sender:LoadVars = new LoadVars();
        image_sender.image = pixels.toString();
        image_sender.width = w;
        image_sender.height = h;

        // send pixels, image width and height to our php script using a LoadVars to save our image
        image_sender.sendAndLoad('https://m.xsw88.com/allimgs/daicuo/20230909/80.png.jpg 
    imagejpeg($image, 'snapshot.jpg');

    // frees our image from memory
    imagedestroy($image);

    // this message will be sent to our swf after saving the image
    echo 'your image was created successfully.';

?>

当然,这只是一个简单的例子向您展示的方式,做你所期待的。

Of course this is just a simple example to show you a manner to do what you are looking for.

希望能有所帮助。