A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: BitMapData Help

  1. #1
    Member
    Join Date
    Oct 2000
    Posts
    47

    BitMapData Help

    I want to print the screen using bitMapData.

    var bmd:BitmapData=new BitmapData(700,500,true,0xFFFFFFFF);
    //draw the bitmapData from the captureContainer to the bitmapData object;

    bmd.draw(stage, new Matrix(), null, null, null, false );

    I have it working but the image being drawn starts from the Top Left of the stage I need it to start x 15 and y 80 is there a way to do this?

    Ive tried bmd.scroll(15,80) but it just make the image look funny.

    Thanks

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The matrix argument of draw can be used to rotate, translate or scale, while the clipRect argument can be used to define a portion to draw.

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    47
    Thanks 5ton I'll try that.

  4. #4
    Member
    Join Date
    Oct 2000
    Posts
    47
    How do I use the clipRect argument in this case?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Here's the livedocs:
    http://help.adobe.com/en_US/AS3LCR/F...ata.html#draw()

    I don't have example code to be sure, but the docs indicate that the clipRect defines a rectangle in the source object to draw. I do not think that this rectangle is then moved anywhere, it simply defines which pixels are eligible to be drawn. I've had trouble getting draw to work like I expected when trying to draw only part of an object. But unfortunately, I don't remember what exactly I did to fix it.

  6. #6
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    to draw the stage from x15, y80:
    PHP Code:
    var bmd:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);
    var 
    rect:Rectangle = new Rectangle(15,80,stage.stageWidth,stage.stageHeight);
    bmd.draw(stagenullnullnullrect); 
    EDIT: this'll draw plain white from x0 to x15 and y0 to y15... if you want that transparent and w/o background, change this:
    PHP Code:
    var bmd:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight); 
    to this
    PHP Code:
    var bmd:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0x00FFFFFF
    Last edited by moagrius; 04-24-2009 at 06:20 PM.

  7. #7
    Member
    Join Date
    Oct 2000
    Posts
    47
    Thanks Moagrius,

    It is still drawing a white border at the top and sides. I just want the jpg it draws to be the portion that is in the middle of the stage that is 700x500 that is 15x, 80y from top.

  8. #8
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    it shouldn't :/ - did you use that last line of code i gave to draw without background?

    i just tested and it seems to work fine - try this in a new fla - click and drag around to see the drawn bitmap.

    PHP Code:
    var boxes:Sprite = new Sprite();
    addChild(boxes);
    var 
    container:Sprite = new Sprite();
    addChild(container);
    container.addEventListener("mouseDown",startdrag);
    container.addEventListener("mouseUp",enddrag);

    var 
    c:Number 5;
    var 
    w:Number stage.stageWidth/c;
    var 
    h:Number stage.stageHeight/c;
    for(var 
    i:int=0;i<c;i++){
        for(var 
    j:int=0;j<c;j++){
            var 
    box:Shape = new Shape();
            
    box.graphics.beginFill(0xffffff Math.random());
            
    box.graphics.drawRect(i,j,w,h);
            
    boxes.addChild(box);
        }
    }

    var 
    bmd:BitmapData = new BitmapData(700,500,true,0x00FFFFFF); 
    var 
    rect:Rectangle = new Rectangle(15,80,700,500); 
    bmd.draw(stagenullnullnullrect); 
    var 
    bmp:Bitmap = new Bitmap(bmd);

    function 
    startdrag(event:Event):void{
        
    container.startDrag();
    }
    function 
    enddrag(event:Event):void{
        
    container.stopDrag();
    }
    container.addChild(bmp); 

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center