Translate

Dynamic Image Load

Thursday, October 13, 2011 Category : 0

var imageLocation:String = File.applicationDirectory.nativePath + "\\assets\\LineBoarderTop.png";
                var borderImage:Image = new Image();
                borderImage.source = imageLocation;
                borderImage.percentHeight = 100;
                borderImage.percentWidth = 100;
                borderImage.scaleContent = true;
                borderImage.maintainAspectRatio = false;
                borderImage.addEventListener(Event.COMPLETE, function(e:Event):void
                {
                    var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
                    // draw white background
                });
                borderImage.load(imageLocation);

pixel value to RGB value extract

Saturday, October 1, 2011 Category : 0

var pixel:uint = bitmap.bitmapData.getPixel(i,j);
 var alpha:uint = pixel >> 24 & 0xff;
  var red:uint = pixel >> 16 & 0xff;
  var green:uint = pixel >> 8 & 0xff;
var blue:uint = pixel & 0xff;

BitmapData to Pixel Value , image pixel value

Category : 0

for(var i:int=startPoint.x; i < endPoint.x;i++)
                {
                    for(var j:int=startPoint.y;j<endPoint.y; j++)
                    {
                        var pixel:uint = bitmap.bitmapData.getPixel(i,j);
                        //var alpha:uint = pixel >> 24 & 0xff;
                        var red:uint = pixel >> 16 & 0xff;
                        var green:uint = pixel >> 8 & 0xff;
                        var blue:uint = pixel & 0xff;

                        var redIntensity:Number = (red / ((green + blue) / 2));
                        if (redIntensity > 1.8)  // 1.5 because it gives the best results
                        {
                            // reduce red to the average of blue and green
                            //bm.SetPixel(i, j, Color.FromArgb((pixel.G + pixel.B) / 2, pixel.G, pixel.B));
                            var colorTrans:ColorTransform = new ColorTransform(90,green,blue);
                            //bitmap.bitmapData.setPixel(i,j,uint((green + blue) / 2));
                            bitmap.bitmapData.setPixel(i,j,colorTrans.color);
                        }

                    }
                }

Flex Pen tool (Drawing canvas)

Sunday, September 25, 2011 Category : 0

package
{
    import mx.containers.Canvas;

    public class LineCanvas extends Canvas
    {
        public var allowDrawing:Boolean=false;
        public var lineColor:uint = 0xFF0000;
        public var lineThickness:int = 2;

        public function LineCanvas()
        {
            super();
        }

    }
}
save this as LineCanvas.as


ad this your main app

private var lm:LineCanvas;

lm = new LineCanvas();
            canvas.addChild(lm);
            this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
            this.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
            this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoving);


private function mouseDown(e:MouseEvent):void
        {
        lm.graphics.moveTo(e.target.mouseX, e.target.mouseY);
        lm.graphics.lineStyle(lm.lineThickness, lm.lineColor, 1, false, CapsStyle.ROUND);
        lm.allowDrawing=true;
        }

        private function mouseMoving(e:MouseEvent):void
        {
            if (lm.allowDrawing)
            {
            lm.graphics.lineTo(e.target.mouseX, e.target.mouseY);
            e.updateAfterEvent();
            }
        }


        private function mouseUp(e:MouseEvent):void
        {
            lm.allowDrawing=false;
        }

Flex File Browser (FileSystemTree ,FileSystemDataGrid )

Category : 0

<mx:HDividedBox>
        <mx:FileSystemTree id="tree"
            width="200" height="100%"
            enumerationMode="directoriesOnly"
            change="dataGrid.directory = File(tree.selectedItem);"
            selectedIndex="0"/>
        <mx:FileSystemDataGrid id="dataGrid"
            width="100%" height="100%"
            directory="{new File('C:\\')}"
            extensions="[skdb,skc]"/>
        </mx:HDividedBox>

Flex change Image source dynamically by coding

Tuesday, September 20, 2011 Category : 0

private function loadImages():void
        {
           
            var source:String  = "your dynamic image path";
            var loader:Loader = new Loader();
            var request:URLRequest = new URLRequest(pageSource);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
            loader.load(request);
        }


private function loadCompleteHandler(e:Event):void
        {
          
            var bitmapData:BitmapData = e.target.content.bitmapData as BitmapData;
            var bitmap:Bitmap = new Bitmap(bitmapData)

            image0.source = bitmap; // where image0 is your mxml file control
            image0.validateNow();
      }

Flex get Mac Address

Monday, September 19, 2011 Category : 0

    import __AS3__.vec.Vector;

    import flash.net.NetworkInfo;
    import flash.net.NetworkInterface;


public function getMacID():ArrayCollection
        {
            var MacAddress:String;
            var ni:NetworkInfo = NetworkInfo.networkInfo;
            var interfaceVector:Vector.<NetworkInterface> = ni.findInterfaces();
            for each (var item:NetworkInterface in interfaceVector)
            {
                var child:NetworkInterface = item as NetworkInterface;
                MacAddress = child.hardwareAddress;
                break;
            }
            return MacAddress;
        }

Powered by Blogger.