4 Replies Latest reply on Nov 20, 2008 7:06 PM by atta707

    Color query, at specific point on screen

    CmdrDoc
      I need to query the color value at a specific x,y point on the global stage, regardless of whether there is an image/canvas/etc there or not. I'd use getPixel(x,y) but that depends on there being BitmapData to check, and like I said: I want to investigate regardless of screen content.

      Can anyone help? Thanks
        • 1. Re: Color query, at specific point on screen
          atta707 Level 2
          Here is how you'll take a snapshot of your application:

          var app:Application = Application.application as Application;
          var bmd:BitmapData = new BitmapData(app.width, app.height);
          bmd.draw(app);
          var bm:Bitmap = new Bitmap(bmd);
          var uic:UIComponent = new UIComponent();
          uic.addChild(bm);
          addChild(uic);

          You can change 'app' in above code with stage and it should work. the most important piece for you is the instance of BitmapData; this class methods like getPixel and getPixel32 that might do the trick for you!

          Hope this helps.

          ATTA
          • 2. Re: Color query, at specific point on screen
            Level 7

            "CmdrDoc" <webforumsuser@macromedia.com> wrote in message
            news:gg40ag$hfa$1@forums.macromedia.com...
            >I need to query the color value at a specific x,y point on the global
            >stage,
            > regardless of whether there is an image/canvas/etc there or not. I'd use
            > getPixel(x,y) but that depends on there being BitmapData to check, and
            > like I
            > said: I want to investigate regardless of screen content.
            >
            > Can anyone help? Thanks

            Not sure if this is the best way, but if you tke an ImageSnapShot, you'd
            have BitmapData.


            • 3. Re: Color query, at specific point on screen
              CmdrDoc Level 1
              quote:

              Originally posted by: atta707
              Here is how you'll take a snapshot of your application:

              var app:Application = Application.application as Application;
              var bmd:BitmapData = new BitmapData(app.width, app.height);
              bmd.draw(app);
              var bm:Bitmap = new Bitmap(bmd);
              var uic:UIComponent = new UIComponent();
              uic.addChild(bm);
              addChild(uic);

              You can change 'app' in above code with stage and it should work. the most important piece for you is the instance of BitmapData; this class methods like getPixel and getPixel32 that might do the trick for you!

              Hope this helps.

              ATTA


              This worked, thanks! In order to gain a bit of speed (maybe) can a certain area (say a canvas) be snapshot into the BitmapData area, instead of the entire app window?
              • 4. Re: Color query, at specific point on screen
                atta707 Level 2
                Absolutely. You can and you should. BitmapData.draw() method takes an instance of IBitmapDrawable, an interface that's implemented by DisplayObject thru which it trickles down to almost every Flex component.

                So pass away any display object to the draw() method and you'll have smaller bit map hence faster processing.

                ATTA