After rotating an image I am unable to correctly save it locally with
the new dimensions.

The width and height of the image remain as the same original
non-rotated image, although visually it updates fine.

I'm sure I'm missing something very simple here. Any help greatly
appreciated. Targets player 10.0.12 / 3.2 SDK.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
     layout="absolute">

     <mx:Script>
         <![CDATA[
             import mx.graphics.ImageSnapshot;
             import mx.graphics.codec.JPEGEncoder;
             import flash.geom.Matrix;
             import flash.display.*;

             private function rotate():void
             {
                 var matrix : Matrix = img.transform.matrix;
                 var offSetWidth : Number = img.width / 2;
                 var offSetHeight : Number = img.height / 2;

                 matrix.translate(-offSetWidth, -offSetHeight);
                 matrix.rotate(90*(Math.PI/180));
                 matrix.translate(offSetWidth, offSetHeight);
                 img.transform.matrix = matrix;
             }

             private function addDs():void
             {
                 var ds : DropShadowFilter = new DropShadowFilter();
                 img.filters = [ ds ];
             }

             private function saveByteArray():void
             {
                 var jpg:JPEGEncoder = new JPEGEncoder();
                 var fileReference : FileReference = new FileReference();
                 var bitmapData:BitmapData = new BitmapData(img.width,
img.height);
                 bitmapData.draw(img, img.transform.matrix);
                 var bitmap : Bitmap = new Bitmap(bitmapData);
                 var byteArray:ByteArray = jpg.encode(bitmapData);
                 fileReference.save(byteArray, 'google.jpg');
             }

             private function saveImageSnapshot():void
             {
                 var fileReference : FileReference = new FileReference();
                 var jpg : JPEGEncoder = new JPEGEncoder();
                 var imageSnap:ImageSnapshot =
ImageSnapshot.captureImage(imgHolder, 0, jpg);
                 fileReference.save(imageSnap.data, "google.jpg");
             }
         ]]>
     </mx:Script>

     <mx:HBox>

         <mx:Button id="btnRotate"
         label="Rotate"
         click="rotate()"/>

         <mx:Button id="btnAddDs"
         label="Drop Shadow"
         click="addDs()"/>

         <mx:Button id="btnSaveByteArray"
             label="Save as ByteArray"
             click="saveByteArray()"/>

         <mx:Button id="btnSaveImageSnapshot"
             label="Save as Snapshot"
             click="saveImageSnapshot()"/>
     </mx:HBox>

     <mx:Box id="imgHolder"
             backgroundColor="red"
             horizontalCenter="0"
             verticalCenter="0">

         <mx:Image id="img"
             source="http://www.google.com/intl/en_ALL/images/logo.gif"/>

     </mx:Box>

</mx:Application>

Reply via email to