Skip navigation
Currently Being Moderated

Bitmap Data

Apr 29, 2012 11:48 PM

Hi,

 

     I would like to know how to copy a portion of an image in an irregular shape using bitmap data or any other function. Kindly let me know if you need further explanation in this.

 

Regards,

Kameshwaran A.

 
Replies
  • Currently Being Moderated
    Apr 30, 2012 12:10 AM   in reply to A.kameshwaran

    You will get portion of an image using BitmapData class method copyPixels(), refer the syntax:



    copyPixels
    (sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, alphaBitmapData:BitmapData = null, alphaPoint:Point = null, mergeAlpha:Boolean = false)

    So in that case you have to define the portation that you expect from the image bitmapdata.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 30, 2012 12:35 AM   in reply to A.kameshwaran

    For irregular shape there are two possible way:

     

    1. Using mask

    2. Uing complex mathematical formulas to fill each pixel in a bitmap data.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 30, 2012 2:36 AM   in reply to A.kameshwaran
     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 30, 2012 1:04 PM   in reply to A.kameshwaran

    if you can convert your irregular shape to a movieclip, you use use the beginBitmapFill() method.

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    May 1, 2012 10:51 PM   in reply to A.kameshwaran

    import flash.geom.Point;

    import flash.display.BitmapData

    var bmp:BitmapData = BitmapData.loadBitmap("bmpID");

    var img:MovieClip = createEmptyMovieClip("img",0);

    img.attachBitmap(bmp,0);

     

    var mc:MovieClip = this.createEmptyMovieClip("mc",1);

    var ptA:Array = [];

     

     

    img.onMouseDown = function(){

        this.onMouseUp = function(){

            //delete this.onMouseDown

            delete this.onEnterFrame;

        }

        var pt:Point = new Point(_xmouse,_ymouse);

        ptA.push(pt);

        this.moveTo(pt.x,pt.y);

        this.onEnterFrame = function(){

            var pt:Point = new Point(_xmouse,_ymouse);

            ptA.push(pt)

            with(this){

                lineStyle(1,0x000000);

                lineTo(pt.x,pt.y);

            }

        }

    }

    this.onMouseUp = function(){

        mc.beginBitmapFill(bmp);

        mc.moveTo(ptA[0].x,ptA[0].y);

        for(var i:Number=1;i<ptA.length;i++){

            mc.lineTo(ptA[i].x,ptA[i].y);

        }

        mc.endFill();

        ptA.length = 0;

    }

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    May 2, 2012 6:36 AM   in reply to A.kameshwaran

    that should be a bitmap with linkage id = "bmpID"

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    May 3, 2012 5:43 AM   in reply to A.kameshwaran

    if you don't want the bitmap on-stage, use:

     

    import flash.geom.Point;

    import flash.display.BitmapData

    var bmp:BitmapData = BitmapData.loadBitmap("bmpID");

    var img:MovieClip = createEmptyMovieClip("img",0);

    //img.attachBitmap(bmp,0);

     

    var mc:MovieClip = this.createEmptyMovieClip("mc",1);

    var ptA:Array = [];

     

     

    img.onMouseDown = function(){

        this.onMouseUp = function(){

            //delete this.onMouseDown

            delete this.onEnterFrame;

        }

        var pt:Point = new Point(_xmouse,_ymouse);

        ptA.push(pt);

        this.moveTo(pt.x,pt.y);

        this.onEnterFrame = function(){

            var pt:Point = new Point(_xmouse,_ymouse);

            ptA.push(pt)

            with(this){

                lineStyle(1,0x000000);

                lineTo(pt.x,pt.y);

            }

        }

    }

    this.onMouseUp = function(){

        mc.beginBitmapFill(bmp);

        mc.moveTo(ptA[0].x,ptA[0].y);

        for(var i:Number=1;i<ptA.length;i++){

            mc.lineTo(ptA[i].x,ptA[i].y);

        }

        mc.endFill();

        ptA.length = 0;

    }

     

    // here's the a file with that code:  http://www.kglad.com/Files/forums/bmpFill.fla

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    May 3, 2012 6:01 AM   in reply to A.kameshwaran

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points