How to convert component to Image in flex?

157 views Asked by At

We know using file reference save method we can save the component as image in flex 3, but i am using flex 3.0 version, i did not get the save method in file reference class. Its available on flex 3.4.0 onwards.Do we have any other option to make the component to image in flex 3.0 compiler using flex builder IDE?

Thanks in advance

2

There are 2 answers

1
Yasuyuki  Uno On

If this case allows to use HTML5, it could be possible.

    public function capturePage(): void
    {
        var bmp:BitmapData = new BitmapData(this.width, this.height);
        bmp.draw(this, new Matrix());

        // convert to JPEG.
        var fileData:ByteArray = new JPEGEncoder().encode(bmp);

        var base64: Base64Encoder = new Base64Encoder();
        base64.encodeBytes(fileData);

        ExternalInterface.call("saveAsImage", "data:image/jpeg;base64,"+base64.toString());
    }

index.template.html

<title>${title}</title>
<script language="JavaScript" type="text/javascript">
function saveAsImage(value)
{
    // open new window. You will be able to save as image.
    window.open(value);

    // or use HTML5 FileWriter API here.
}
</script>
<script src="AC_OETags.js" language="javascript"></script>
0
venkat On
        private function doSave():void 
        {              
             var bmp:BitmapData = new BitmapData(canvas.width,canvas.height);
            bmp.draw(canvas,new Matrix());

            var filedate:ByteArray = new JPEGEncoder().encode(bmp);

            var uploadURL:URLRequest = new URLRequest();
            uploadURL.url = parentApplication.ServerUrl+"...../imageupload.php?fileName="+yourfilename;
            uploadURL.contentType = 'application/octet-stream';
            uploadURL.method = URLRequestMethod.POST;
            uploadURL.data = filedate;
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, completeHandler);                
            urlLoader.load(uploadURL);
        }

PHP File : imageupload.php

    <?php
      $fileName = $_REQUEST['fileName'] . ".jpeg";
      $fp = fopen( "../tempfolder/".$fileName, 'wb' );
      fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
      fclose( $fp );
     ?>