cropping image

8 views
Skip to first unread message

Ramesh Vavila

unread,
Jan 18, 2011, 5:50:44 AM1/18/11
to flex_...@googlegroups.com

Hi Everybody

How to Crop the selected area of image in flex 4 can help me in this. if any reference code please send me that code url.

Thanks in Advance
ramesh v

sachin potdar

unread,
Jan 24, 2011, 5:00:59 AM1/24/11
to flex_...@googlegroups.com
Hello Ramesh,

Here is some sample I did image cropping in my application.Please refer it.

private function applyCrop( event:MouseEvent ) : void
            {               
                if(finalImgBx.numChildren > 0)
                {
                    finalImgBx.removeAllChildren();
                }

                var img:Image = imgCnvsFront.getChildAt(0) as Image;
                _bitmap = Bitmap(img.content );
                _bitmapData = _bitmap.bitmapData;
               
                var tmp:BitmapData = new BitmapData(_cropper.width, _cropper.height, true, 0x00000000);
                var posPoint:Point = new Point(0,0);
                tmp.copyPixels(_bitmapData,
                    new Rectangle(_cropper.x, _cropper.y, _cropper.width, _cropper.height),
                    posPoint);
               
               
                /* imgCnvs.scrollRect = new Rectangle(_cropper.x+1,_cropper.y+1,_cropper.width,_cropper.height);
                var tmp:BitmapData = new BitmapData(_cropper.width - 1, _cropper.height - 1);
                tmp.copyPixels(_bitmap); */
                finalBmp = new Bitmap(tmp);
                finalBmp.height = _cropper.height - 1;
                finalBmp.width = _cropper.width - 1;
                finalImage = new Image();
                finalImage.height = _cropper.height - 1;
                finalImage.width = _cropper.width - 1;
                finalImage.source = finalBmp;
                finalImage.setStyle("borderStyle","solid");
               
                if(finalImage.width > finalImage.height)
                {
                    finalImgBx.width = finalImage.width + (finalImage.width*0.5);
                    finalImgBx.height = finalImage.width + (finalImage.width*0.5);
                }
                else
                {
                    finalImgBx.width = finalImage.height + (finalImage.height*0.5);
                    finalImgBx.height = finalImage.height + (finalImage.height*0.5);
                }
                finalImage.x = (finalImgBx.width-finalImage.width)*0.5;
                finalImage.y = (finalImgBx.height-finalImage.height)*0.5;
               
                finalImgBx.addChild(finalImage);
                isScalled = false;
                isAnyOperationPerformed = true;
               
                if(isFlipHorizontal)
                    isLastFlipHorizontal = true;
                else
                    isLastFlipHorizontal = false;
               
                if(isFlipVertical)
                    isLastFlipVertical = true;
                else
                    isLastFlipVertical = false;
            }

Regards,
Sachin Potdar
sachi...@gmail.com



--- On Tue, 18/1/11, Ramesh Vavila <ramesh...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to flex_...@googlegroups.com.
To unsubscribe from this group, send email to flex_india+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

Ramesh Vavila

unread,
Jan 24, 2011, 7:51:51 AM1/24/11
to flex_...@googlegroups.com
Hi sachin

Thank you so much....

Regards,
ramesh v
Reply all
Reply to author
Forward
0 new messages