2 Replies Latest reply on Oct 5, 2010 6:06 AM by mikall1979

    Help with draw method

    mikall1979

      Hello.
      I'm trying to make a hardcopy of an image and then  rotate.
      I'm trying to use the draw  method, but probably do not understand something in its use. What's wrong with these few lines of code?

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                     creationComplete="init_app()">
          <fx:Script>
                  <![CDATA[               
                      import flash.display.Bitmap;
                      import flash.display.BitmapData;
                     
                      internal function init_app():void {                   
                          var bd:BitmapData = Bitmap(image.content).bitmapData;
                          var m:Matrix = new Matrix();
                          m.rotate(30);
                          var bd2:BitmapData = new BitmapData(image.content.height, image.content.width);
                          bd2.draw(bd, m);
                          var bitmap:Bitmap = Bitmap(bd2);
                          image.addChild(bitmap);           
                      }               
                  ]]>
          </fx:Script>
          <mx:Image id="image" x="211" y="106" source="file:/D:/test.jpg" width="217" height="290"/> 

       

      Thanks to anyone who can help me.

       

      PS. I use Flex 4

        • 1. Re: Help with draw method
          BhaskerChari Level 4

          Hi Mikall,

           

          Try this function instead...

           


          internal function init_app():void {


          var bd:Bitmap = Bitmap(image.content);


          var m:Matrix = new Matrix();

          m.rotate(30);

           


          var bd2:BitmapData = new BitmapData(image.content.height, image.content.width);

          bd2.draw(bd, m);

           


          var bitmap:Bitmap = new Bitmap(bd2);


          //image.addChild(bitmap);


          image.source = bitmap;

           

          }

           

           

           

           

           

          Thanks,

          Bhasker

          • 2. Re: Help with draw method
            mikall1979 Level 1

            Ok, this could help me.. but:

            screen.JPG

            1) changes the scale factor;

            2) changes the original size (in pixel)

            3) appears to truncate the image (bottom left corner)

             

            Why this simple function doesn't rotate the image properly!!!???


            internal function init_app():void {
                                larg_start.text = image.width.toString();
                                alt_start.text = image.height.toString();
                                var bd:Bitmap = Bitmap(image.content);                           
                                var m:Matrix = new Matrix();
                                //rotate around the center of the image
                                var centerX:Number = image.width / 2;
                                var centerY:Number = image.height /2;
                                m.translate(-1 * centerX, -1 * centerY);                   
                                m.rotate(1);
                                m.translate(centerX, centerY);
                                var bd2:BitmapData = new BitmapData(image.content.height, image.content.width);                   
                                bd2.draw(bd, m);                                   
                                var bitmap:Bitmap = new Bitmap(bd2);
                                image2.source = bitmap;
                                larg_stop.text = image2.width.toString();
                                alt_stop.text = image2.height.toString();               
                            }

             

            Please help me....