actionscript 3 - Save JPG from CDROM to PC -


i using following function save output swf , send php page creates jpg, problem if there not internet connection , swf in cdrom can save function used in flash outputs jpg , save on computer.

in short can save movieclip output jpg

  /**     screenshot , jpg output     **/     import flash.display.bitmapdata;     import flash.geom.matrix;      //buttons handlers. should add function because delegate doesn't allow pass parameters     shaf.onpress = mx.utils.delegate.create(this,makeshadow);      //helper functions pass parameters     function makeshadow() { capture(0) }      /*     create function takes snapshot of video object whenever called     , shows in different clips     */     function capture(nr){      this["snapshot"+nr] = new bitmapdata(abc._width,abc._height);        //the bitmap object no transformations applied      this["snapshot"+nr].draw(abc,new matrix());      var t:movieclip = createemptymovieclip("bitmap_mc"+nr,nr);       //positions clip in correct place      //t._x = 350; t._y = 10+(nr*130); t._xscale = t._yscale = 50       //display specified bitmap object inside movie clip      t.attachbitmap(this["snapshot"+nr],1);     output(nr);      //attachmovie("print_but", "bot"+nr, 100+nr, {_x:t._x+t._width+50, _y:t._y+t._height/2})      }     //create new bitmapdata, resize 50 %, pass image data server script     // using loadvars object (large packet)     function output(nr){       //here copy pixels data       var pixels:array = new array()       //create new bitmapdata       var snap = new bitmapdata(this["snapshot"+nr].width, this["snapshot"+nr].height);        //matrix scale new image       mymatrix = new matrix();       mymatrix.scale(1, 1)         //copy image       snap.draw(this["snapshot"+nr],  mymatrix);        var w:number = snap.width, tmp       var h:number = snap.height       //build pixels array       for(var a=0; a<=w; a++){        for(var b=0; b<=h; b++){         tmp = snap.getpixel32(a, b).tostring(16)         //if(tmp == "-fcffff")         //{          //tmp="-ff0000";         //}          pixels.push(tmp.substr(1))        }       }       //create loadvars object , pass data php script       var output:loadvars = new loadvars()       output.img = pixels.tostring()       output.height = h       output.width = w       //the page (and movie itself) should in server work       output.send("show.php", "output", "post")         }     stop() 

since have bitmapdata, easy. modifying output function:

//copy image snap.draw(this["snapshot"+nr],  mymatrix);   //now check if want save jpg instead of sending data server if (runningfromcdrom) {     var encoder:jpegencoder = new jpegencoder();     var bytes:bytearray = encoder.encode(snap);     var file:filereference = new filereference();     file.save(bytes); } else {     // ...the rest of output method... } 

how determine runningfromcdrom value you. if swf being run inside html document, best way tell if program being run cd-rom specify in flashvars.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -