15 Replies Latest reply: May 3, 2012 6:01 AM by kglad RSS

    Bitmap Data

    A.kameshwaran

      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.

        • 1. Re: Bitmap Data
          Bharat Patel Community Member

          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.

          • 2. Re: Bitmap Data
            A.kameshwaran Community Member

            Hi Bharat,

                 Thanks for the information. I have used the above the syntax to crop the image with rectangle points. But, i need to know how can i use the above syntax to copy the irregular shape.

             

            For ex:

             

            for rect i have used the below code

             

                           desBmp.copyPixels(srcBmp,new Rectangle(x, y, w, h),new Point(0, 0));

             

            If i want to copy for triangle / polystar / user defined points(polygon), in these case how can i use the above the sytax.

             

            Regards,

            Kameshwara A.

            • 3. Re: Bitmap Data
              Bharat Patel Community Member

              For irregular shape there are two possible way:

               

              1. Using mask

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

              • 4. Re: Bitmap Data
                A.kameshwaran Community Member

                Thanks for the suggestion. Is it possible for you to give some tips for the second point or the reference link i can learn, how to fil the pixel by pixel using bitmap. It will be very help ful for me to proceed further.

                • 6. Re: Bitmap Data
                  A.kameshwaran Community Member

                  The link you have given is in AS3 method.

                  • 7. Re: Bitmap Data
                    kglad MVP

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

                    • 8. Re: Bitmap Data
                      A.kameshwaran Community Member

                      hi

                           I dont know how to extract that particular content and convert them in to movieclip.

                       

                      To be much clear about my requirement,

                       

                      I have 600*800 image and i loaded in to the interface. I am allowing the user to draw the particular portion over the image inorder have that particular portion and save it in their gallery.

                       

                      Previously i have given only rectangle option so there's no issue for me in doing that using bitmap.

                       

                      But now i need to give the free tool so that user can choose any part like text or face  or ..

                       

                      once user has drawn the portion, i will having the co ordinate like below,

                       

                      x1y1,x2y2, x3y3,x4y4,x5y5,x6y6, x7y7,x8y8

                       

                      i need to copy the portion that covers in the coordinate and i need to show the preview to the user.

                       

                      I hope it will explain my prolem prity clear.

                      • 9. Re: Bitmap Data
                        kglad MVP

                        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;

                        }

                        • 10. Re: Bitmap Data
                          A.kameshwaran Community Member

                          I have checked but it is not working for me. Let me tell you what i have done.

                          I have copied this code and put in the test file. in library i have a movieclip with linkage id "bmpID" and i have placed a image inside.

                           

                          when i publish i couldn't able to see the image but i can draw. Once i have drawn using line. i can't see the image of the portion.

                           

                          I don't know what mistake i have made. Guide me.

                          • 11. Re: Bitmap Data
                            kglad MVP

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

                            • 12. Re: Bitmap Data
                              A.kameshwaran Community Member

                              I have bitmap in the library and i have given the linkage id for that. But, now the image is viewable. But i couldn't able to see the drawing line and on the mouse up nothing is happening.

                               

                              kindly tell me how to achieve it.

                              • 13. Re: Bitmap Data
                                kglad MVP

                                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

                                • 14. Re: Bitmap Data
                                  A.kameshwaran Community Member

                                  Thanks for your patience and for the time. Previous one also worked for me now. Because of the depth only it is not working and now i have figure it out. This is the concept that i am actually looking and i got it.

                                  • 15. Re: Bitmap Data
                                    kglad MVP

                                    you're welcome.