+ Reply to Thread
Results 1 to 3 of 3

Resizing bitmaps and retrieving bitmapdata

This is a discussion on Resizing bitmaps and retrieving bitmapdata within the Actionscript 3.0 newbies forums, part of the Flash English category; I am trying to load an image from an iPhone camera roll and then resize it to 480x320 to use ...

  1. #1
    Junior Member Settled In Seeward is on a distinguished road
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Resizing bitmaps and retrieving bitmapdata

    I am trying to load an image from an iPhone camera roll and then resize it to 480x320 to use it in another function. I got the image loading and can even do a simple resize that works(displays correctly in a test) but when I pass the bitmap data to the next function, it only displays the top left section(480x320) of the original sized bitmap, not the full resized bitmap.

    I am new to AS3 but I am thinking that I am only resizing the display of the bitmap and then the function gets passed the BitmapData, which I am assuming is not being changed so when the next function adds it to the display list the screen size (480x320) is cropping off the rest of the image.

    Could someone help me with a simple way to:

    1 resize the bitmapData of an already loaded bitmap named image
    2 pass the new resized bitmapData to the next function makePuzzle(image.bitmapData);

    Any help would be appreciated!
    Last edited by Seeward; 09-02-12 at 10:01. Reason: Spelling error

  2. #2
    Junior Member Settled In Seeward is on a distinguished road
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Re: Resizing bitmaps and retrieving bitmapdata

    here's the code I am using currently

    public function resize(event:Event):void {
    var image:Loader = event.currentTarget.loader as Loader;
    var scale:Number;

    if(image.width > image.height) {
    scale = stage.stageHeight / image.width;
    image.scaleY = scale;
    image.scaleX = scale;
    image.x = stage.stageWidth;
    image.rotation = -90;
    addChild(image);
    }
    else {
    scale = stage.stageHeight / image.width;
    image.scaleY = scale;
    image.scaleX = scale;
    addChild(image);

    }
    // set number of puzzle pieces
    pieceWidth = image.width/numPiecesHoriz;
    pieceHeight = image.height/numPiecesVert;

    // cut into puzzle pieces
    makePuzzlePieces(image.bitmapData);

    // shuffle them
    shufflePuzzlePieces();
    }


    // cut bitmap into pieces
    public function makePuzzlePieces(bitmapData:BitmapData) {
    puzzleObjects = new Array();
    for(var x:uint=0;x<numPiecesHoriz;x++) {
    for (var y:uint=0;y<numPiecesVert;y++) {
    // skip blank spot
    if (blankPoint.equals(new Point(x,y))) continue;

    // create new puzzle piece bitmap and sprite
    var newPuzzlePieceBitmap:Bitmap = new Bitmap(new BitmapData(pieceWidth,pieceHeight));
    newPuzzlePieceBitmap.bitmapData.copyPixels(bitmapD ata,new Rectangle(x*pieceWidth,y*pieceHeight,pieceWidth,pi eceHeight),new Point(0,0));
    var newPuzzlePiece:Sprite = new Sprite();
    newPuzzlePiece.addChild(newPuzzlePieceBitmap);
    addChild(newPuzzlePiece);

    // set location
    newPuzzlePiece.x = x*(pieceWidth+pieceSpace) + horizOffset;
    newPuzzlePiece.y = y*(pieceHeight+pieceSpace) + vertOffset;

    // create object to store in array
    var newPuzzleObject:Object = new Object();
    newPuzzleObject.currentLoc = new Point(x,y);
    newPuzzleObject.homeLoc = new Point(x,y);
    newPuzzleObject.piece = newPuzzlePiece;
    newPuzzlePiece.addEventListener(MouseEvent.CLICK,c lickPuzzlePiece);
    puzzleObjects.push(newPuzzleObject);
    }
    }
    }
    Last edited by Seeward; 09-02-12 at 13:14.

  3. #3
    Junior Member Settled In Seeward is on a distinguished road
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Re: Resizing bitmaps and retrieving bitmapdata

    sorry for the multiple posts but I noticed that I am actually declaring the image var with this code instead


    var image:Bitmap = Bitmap(event.target.loader.content);

    not as loader (above in resize function - 1st line)

    var image:Loader = event.currentTarget.loader as Loader;

+ Reply to Thread

Similar Threads

  1. bitmap e bitmapData
    By Inghe in forum Actionscript 3.0 base
    Replies: 2
    Last Post: 25-06-10, 10:36
  2. retrieving instance name of buttons from array and change it state
    By simplyJohn in forum Actionscript 3.0 newbies
    Replies: 3
    Last Post: 20-01-10, 14:55
  3. bitmapData
    By feder in forum Flash Italiano
    Replies: 2
    Last Post: 27-01-09, 13:54
  4. Esportare una bitmapdata
    By masky in forum Actionscript 3.0 avanzato
    Replies: 6
    Last Post: 02-04-08, 07:21
  5. BitmapData.draw() da movieclip
    By aguia in forum Actionscript 3.0 avanzato
    Replies: 7
    Last Post: 31-08-07, 06:24

Tags for this Thread

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