3 Replies Latest reply on May 28, 2010 9:30 AM by cyber0897

    how do i resize the image getting captured by ImageSnapshot???

    cyber0897 Level 1

      hey guys... so im taking an image of a movie clip using ImageSnapshot.captureBitmapData(myClip);

       

      i need to resize the bitmap data that i get back, the size needs to be 720X486

       

      the code i have is...

       

      var myClip:MovieClip = event.target as MovieClip;
      
      var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(myClip);
      var pngEncode:PNGEncoder = new PNGEncoder();
      var ba:ByteArray = pngEncode.encode(imageBitmapData);
      

       

       

      any ideas??? i tried to use the matrix.scale, but i guess i didnt understand on how to use it properly...

       

      any help is greatly appretiated!!

       

      thanks

        • 1. Re: how do i resize the image getting captured by ImageSnapshot???
          BhaskerChari Level 4

          Hi,

           

          You can also use the below approach to  capture the BitmapData of your moviclip(myClip).

           

          So that you can make use of matrix class to resize the bitmap image.

           

               var myClip:MovieClip = event.target as MovieClip;

           

               var imageBitmapData:BitmapData = new BitmapData(myClip.width,myClip.height);
              var pngEncode:PNGEncoder = new PNGEncoder();
              var ba:ByteArray = pngEncode.encode(imageBitmapData);
              var m:Matrix = new Matrix();
              imageBitmapData.draw(myClip,m);
              m.scale(1.2,1);

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: how do i resize the image getting captured by ImageSnapshot???
            David_F57 Level 5

            hi,

             

            so hows the sleep going

             

            This function will just take your display object and return what you want, pass the final width you need and it works out the scaling for you, you could make it more complex by comparing say width and final height to calculate 'best fit' but hey...

             

            David.

             

            private function rescale(content:DisplayObject, width:int): BitmapData

            {

            var scale:Number=width/content.width;

            var bd : BitmapData = new BitmapData(content.width*scale,content.height*scale);

            var mt:Matrix=new Matrix();

            mt.scale(scale,scale);

            bd.draw(content,mt);

            return bd;

            }

            • 3. Re: how do i resize the image getting captured by ImageSnapshot???
              cyber0897 Level 1

              hey guys... thanks you for the replys...

               

              i tried both of your codes, and with a little modification to david's code it worked like a charm!!! thanks you soo much guys!!! really appretiate it!!

               

              oh and the sleep sucks man... but thank god for the weekend soo exited to be passed out for 15 hours tommorow hehe