Hi Learn about image masking from this link and get sample source from there.... I think It may help You... http://www.insideria.com/2008/01/flex-graphics-tricks-part-1-ma.html
On Fri, Oct 23, 2009 at 10:20 AM, santhosh kumar <[email protected]> wrote: > Hicreate a mask Like heart Shape Then apply the mask to image.... > here I have given the code for cropping image at regular shape. Try this. > This will not crop image like heart shape... > It Will crop the selected area... I think Only The mask can help you to > crop the image like heart shape... > > here is the code... > > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" initialize="initNew()" width="320" height="370"> > > <mx:Script> > <![CDATA[ > import mx.rpc.soap.LoadEvent; > import mx.controls.Alert; > import mx.controls.Image; > > private const image_path:String = "Your Image Source"; > private var loader:Loader; > private var request:URLRequest; > > private var loadBD:BitmapData; > private var cropBD:BitmapData; > private var startPoint:Point; > private var posPoint:Point; > private var square: int; > private var mtrx: Matrix; > > private function initNew():void > { > loader=new Loader(); > request=new URLRequest(image_path); > loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete); > > loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,handleError); > loader.load(request); > } > private function handleError(event:IOErrorEvent):void > { > Alert.show(event.text); > } > private function onComplete(event:Event):void { > loadBD = Bitmap(event.currentTarget.content).bitmapData; > > imageHolder.graphics.beginBitmapFill(loadBD); > imageHolder.graphics.drawRect(0, 0, loadBD.width, loadBD.height); > imageHolder.graphics.endFill(); > //make initial image > drawImage(); > } > private function drawImage():void > { > //crop square > startPoint = new Point(xSelector.value,ySelector.value); > square = sizeSelector.value; > cropImage(startPoint,square); > //resize image and show it > resizeImage(); > } > > private function cropImage(startPoint:Point, squareSize:int):void > { > // Make a new bitmap data using square size > cropBD = new BitmapData(squareSize, squareSize, true, 0x00000000); > // Position where will be dispayed in the new object, in our case > (0,0) > posPoint = new Point(0,0); > // copy pixels from loaded bitmap data to our new object > cropBD.copyPixels(loadBD, new Rectangle(startPoint.x, startPoint.y, > squareSize, squareSize), posPoint); > > //draw crop area selected > imageCrop.graphics.clear(); > imageCrop.graphics.lineStyle(1, 0xFFFFFF,0.5); > imageCrop.graphics.drawRect(0, 0, cropBD.width, cropBD.height); > imageCrop.move(imageHolder.x + startPoint.x, imageHolder.y + startPoint.y); > > } > > private function resizeImage():void > { > // make scale matrix > mtrx = new Matrix(); > mtrx.scale( imageView.width/cropBD.width , > imageView.height/cropBD.height); > > // Fill in image > imageView.graphics.clear(); > imageView.graphics.beginBitmapFill(cropBD,mtrx,false); > imageView.graphics.drawRect(0, 0, imageView.width, imageView.height); > imageView.graphics.endFill(); > } > > > ]]> > </mx:Script> > > > <mx:Canvas id="imageView" x="210" y="10" width="100" height="100" /> > <mx:Canvas id="imageHolder" x="10" y="120" width="300" height="240" /> > <mx:Canvas id="imageCrop" x="0" y="0" width="0" height="0" /> > <mx:Label x="10" y="15" width="60" text="X position"/> > <mx:HSlider id="xSelector" x="80" y="10" width="120" minimum="0" > maximum="290" snapInterval="10" enabled="true" value="170" > change="drawImage()" /> > <mx:Label x="10" y="55" width="60" text="Y position"/> > <mx:HSlider id="ySelector" x="80" y="50" width="120" minimum="0" > maximum="230" snapInterval="10" enabled="true" value="20" > change="drawImage()" /> > <mx:Label x="10" y="95" width="60" text="Area size"/> > <mx:HSlider id="sizeSelector" x="80" y="90" width="120" minimum="10" > maximum="240" snapInterval="10" enabled="true" value="100" > change="drawImage()" /> > </mx:Application> > > > try this... if you have any doubt in this ask me... > don't forget to give the image source in Image_path constant that i have > used.... > > all the best... > > > On Thu, Oct 22, 2009 at 4:49 PM, suku <[email protected]> wrote: > >> >> Hi all, >> >> Can anybody help me out how to crop Images into heart shape. >> >> Thanks, >> Sukumar. >> >> >> >> > > > -- > Think Different... Be Different... > **********Santo************* > +91-9994995363 > -- Think Different... Be Different... **********Santo************* +91-9994995363 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

