Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: capturing bounds and storing values for jpeg capture

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default capturing bounds and storing values for jpeg capture

    if I create a rect object and use startDrag and stopDrag

    with the function that controls MouseUp I can
    trace the size and position with:


    trace("rect bounds ", rect.getBounds(this));


    I would like to do something like assign a variable like

    var Capture:Number;

    and then place the values from rect.getBounds in it

    Capture=rect.getBounds(this);
    and then

    trace(Capture);
    but that won't work because I think it's got 4 values at once to store

    I have some code from learnactionscript.com and seen lee brimlow's demo on gotoand learn about taking a snapshot of a video.

    I am trying to reverse engineer something I have seen here

    so far I have code for the basic jpeg capture,




    import com.adobe.images.JPGEncoder;
    var Capture:Number;
    var rect:Sprite=new Sprite();




    rect.graphics.beginFill(0x0000FF,1);
    rect.graphics.drawRect(250,250,50,50);
    rect.graphics.endFill();
    rect.alpha=.25;
    addChild(rect);


    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed, false, 0, true);

    function onKeyPressed(evt:KeyboardEvent):void
    {
    switch(evt.keyCode)
    {


    case Keyboard.SPACE:

    trace("space");
    var paintGrab:BitmapData = new BitmapData (50,50);



    paintGrab.draw(canvas);
    var myEncoder:JPGEncoder = new JPGEncoder(100);
    var byteArray:ByteArray = myEncoder.encode(paintGrab);

    var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");

    var saveJPG:URLRequest = new URLRequest ("savejpg.php?img=mydrawing.jpg");
    saveJPG.requestHeaders.push(header);
    saveJPG.method = URLRequestMethod.POST;
    saveJPG.data = byteArray;

    navigateToURL(saveJPG, "_blank");


    break;
    case Keyboard.ENTER:

    trace("enter");
    break;

    }

    }


    //in this sample, canvas is a movie clip on the stage
    rect.addEventListener(MouseEvent.MOUSE_UP,dragnot);
    function dragnot(evt:MouseEvent):void{
    rect.stopDrag();

    trace("rect bounds ", rect.getBounds(this));

    // rect.getBounds(this);
    //Capture=rect.getbounds(this)
    //trace(Capture);
    }
    rect.addEventListener(MouseEvent.MOUSE_DOWN,dragcam);
    function dragcam(evt:MouseEvent):void{
    rect.startDrag();
    }

    there is also some php that runs with it that I didn't post -I got it to work but I can't control an image capture inside bouunds coords -as in I don't want a complete screenshot of the whole stage.
    Last edited by evan; 09-02-2008 at 05:21 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    but that won't work because I think it's got 4 values at once to store
    You're right... If you trace out what you get back from a getBounds() method call, you'll end up with something like:

    Code:
    (x=100, y=200, w=30, h=40)
    Even if you save that to a variable, there isn't much that you can do with the data in that format. But you can change the format...or at least extract data and create a new format.

    So, if you do something like:
    Code:
    var b = rect.getBounds(this);
    You can acess each of the values individually and then assign them to whatever values you want. Personally, I'd use an array to store all the values. Or create a new object and attach the values to that. Though, if four seperate variables make sense, go ahead.

    Code:
    trace(rect.getBounds(this));
    var b = rect.getBounds(this);
    trace(b.x);
    trace(b.y);
    trace(b.width);
    trace(b.height);
    Hope that helps.

  3. The Following User Says Thank You to Medyman For This Useful Post:

    evan (09-02-2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    yes, that does and it has it's uses too, as in I could trigger events by tracking individual bounds properties x,y,height and width

    but in this line:

    paintGrab.draw(rect.Capture);

    or paintGrab.draw(Capture);

    I can't get the jpeg to be captured on a segment of the stage via the moving rect box which acts as a camera -the way that game works.

    I'm dying to figure out how they did that.

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hey Evan,

    I think this might be of use to you.

  6. The Following User Says Thank You to Medyman For This Useful Post:

    evan (09-02-2008)

  7. #5
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    that's what I want to do later on in the short term I just want to define a rectangular boundry where the capture will take place and export it as a jpg


    var paintGrab:BitmapData = new BitmapData (50,50);

    this only has two parameters defining the size of the square -what about defining where it goes to take the file from?

    myRectangle.graphics.drawRect(beginX, beginY, endX - beginX, endY - beginY);
    lets say I just wanted to have a static set of coords not dynamicly selected by the user I would just plug in the values there right?

    but if I wanted to drw my own rect or move a sprite, trace it's bounds , record the values in variables I could also do it with that line of code -am I over simplifying it?

  8. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by evan View Post
    but if I wanted to drw my own rect or move a sprite, trace it's bounds , record the values in variables I could also do it with that line of code -am I over simplifying it?
    Sure...if you're drawing your own. You can use the code in the example I linked to.

    Code:
    function rectStartingPoint(m:MouseEvent):void  
    {  
       beginX = mouseX;  
       beginY = mouseY;  
      
       stage.removeEventListener(MouseEvent.MOUSE_DOWN, rectStartingPoint);  
       stage.addEventListener(MouseEvent.MOUSE_MOVE, rectDraw);  
    }  
      
    function rectDraw(m:MouseEvent):void  
    {  
       endX = mouseX;  
       endY = mouseY;  
    }
    When you first click to begin drawing, it records that point. When you release, it records that point.

    Then using the formula it posted, it draws the rectangle.

    If you're moving a Sprite and assuming that its registration point is in the upper left hand corner:

    beginX and beginY equal Sprite.x and Sprite.y respectively. endX and endY equal Sprite.x + Sprite.width and Sprite.y + Sprite.height respectively.

    Is that what you're looking for?

  9. The Following User Says Thank You to Medyman For This Useful Post:

    evan (09-02-2008)

  10. #7
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    yes, eventually I want to get there.

    Also I think I can just plug in some values to a sprite that doesn't move -right?

    -as in have a user save their artwork in a drawing pad would that work too -I assume it will.

    (I have two projects in mind for this kind of thing)


    -I'll have to play with it because everything that example does is overkill -and it uses external code (I just starting out with it).

  11. #8
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Code:
    I'll have to play with it because everything that example does is overkill -and it uses external code
    How is it overkill? To me, it seems exactly like what you're doing. Draw a rectangle & copy the source below it. The only difference is that in the example, you're adding the copied bitmap to the displayList whereas you would send it off to the JPGEncoder.

    Also, there is no external code there. Also those imports are of native AS3 classes. The developer there is using a Document class so those import calls are required. If you're using the Flash IDE, you shouldn't have to import any of those.

    Of particular interest to you would be the cropImage() function, I think.

  12. #9
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    cool I woke up at 3:00 am to get started.

    I wasn't sure why all those classes had to be installed -but with external code I guesse you need to do that.

    I'll give a shout if I get stuck.


    thanks.

  13. #10
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by evan View Post
    I wasn't sure why all those classes had to be installed -but with external code I guesse you need to do that.
    Yup...when you're using a Document class or other external classes you have to explicitely import whichever native Flash classes you need. When you're coding within the IDE, Flash does that automatically for you when it complies the SWF.

    If you ever decompile a SWF that you've created using the Flash IDE, you'll see that the import * statements will be there. Of course, you didn't have to write them yourself -- they were automatically added based on which classes you needed in your code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •