Thanks Sathesh its now working On Thu, Nov 26, 2009 at 12:30 AM, sathesh <[email protected]> wrote:
> hi, > > here is an sample application which will help you to understand,.. > taking snapshot of particular area of the image > > In this example a image is loaded into a Image Container user can > click and define the area of snapshot to be taken > the snapshot is displayed in another Image Container > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" creationComplete="init(event)"> > <mx:Script> > <![CDATA[ > import mx.containers.Canvas; > import mx.events.FlexEvent; > import mx.graphics.ImageSnapshot; > import flash.display.* > import flash.geom.Point; > [Bindable] > private var mesg:String > private var x0:Number > private var y0:Number > private var w:Number > private var h:Number > private var temp:Canvas > private function init(e:FlexEvent):void > { > temp=new Canvas() > this.addChild(temp) > temp.x=source.x > temp.y=source.y > mesg="INIT" > this.addEventListener(MouseEvent.MOUSE_DOWN,startDraw) > this.addEventListener(MouseEvent.MOUSE_UP,stopDraw) > } > private function takeSnapshot():void { > var imageBitmapData:BitmapData = > ImageSnapshot.captureBitmapData(source); > var bmpD:BitmapData=new BitmapData(w,h) > var rect:Rectangle=new Rectangle(x0,y0,w,h); > ///*Method_1 > var mat:Matrix=new Matrix() > mat.translate(-x0,-y0) > bmpD.draw(imageBitmapData,mat) > //*/ > /*Method_2 > bmpD.copyPixels(imageBitmapData,rect,new > Point(0,0)) > */ > > snapshotHolder.width=w > snapshotHolder.height=h > snapshotHolder.source = new Bitmap(bmpD); > mesg="SNAPSHOT_TAKEN" > } > private function startDraw(e:MouseEvent):void > { > x0=source.mouseX > y0=source.mouseY > mesg=String(x0)+","+String(y0)+"RECT_START" > this.addEventListener > (MouseEvent.MOUSE_MOVE,defineRectangle) > } > private function stopDraw(e:MouseEvent):void > { > w=source.mouseX-x0 > h=source.mouseY-y0 > if(w<0) > { > x0=source.mouseX > w=Math.abs(w) > } > if(h<0) > { > y0=source.mouseY > h=Math.abs(h) > } > mesg="RECT_STOPPED" > this.removeEventListener > (MouseEvent.MOUSE_MOVE,defineRectangle) > takeSnapshot() > } > private function defineRectangle(e:MouseEvent):void > { > w=source.mouseX-x0 > h=source.mouseY-y0 > mesg=String(w)+","+String(h)+": ONDRAW" > > temp.graphics.clear() > temp.graphics.lineStyle(1,0xff0000,.5) > temp.graphics.drawRect(x0,y0,w,h) > } > ]]> > </mx:Script> > <mx:HBox paddingTop="15" paddingLeft="15"> > <mx:Image source="assets/test.jpg" width="100%" height="100%" > id="source" maintainAspectRatio="true"/> > <mx:Image id="snapshotHolder"/> > </mx:HBox> > <mx:Label text="{mesg}" fontSize="10" paddingLeft="15"/> > </mx:Application> > > -- > > You received this message because you are subscribed to the Google Groups > "Flex India Community" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<flex_india%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/flex_india?hl=en. > > > -- Thanks & Regards Jakir M. Qureshi Software Engineer Saba Software India Pvt. Ltd. -- You received this message because you are subscribed to the Google Groups "Flex India Community" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

