Translate

Home > June 2011

June 2011

Flex Save canvas as JPEG

Wednesday, June 8, 2011 Category : 0

var dpi:Number = 250;
var imageSnapShot:ImageSnapshot = ImageSnapshot.captureImage(TestCanvas, dpi, new JPEGEncoder(), false);
var byteInfo:ByteArray = imageSnapShot.data;
byteInfo.compress();

var imageFile:File = new File(File.applicationDirectory.nativePath + "/Test.jpg");
            var fileStream:FileStream = new FileStream();
            fileStream.open(imageFile, FileMode.WRITE);
            while(fileStream.writeBytes(byteInfo, 0, byteInfo.length))
            {

            };
            fileStream.close();
 ======================================================================
            var targetObject:DisplayObject = TestCanvas;

            var canvasWidth:int = targetObject.width;
            var canvasHeight:int = targetObject.height;

            var bitmapDataCP:BitmapData = new BitmapData(canvasWidth, canvasHeight, true, 0xFFFFFFFF);
            bitmapDataCP.draw(targetObject as IBitmapDrawable);
            targetBitmap = new Bitmap(bitmapDataCP);

            dobookEncoder = new DoBookJPGEncoder();
            dobookEncoder.PixelsPerIteration = 1000;
            dobookEncoder.addEventListener(DoBookCompleteEvent.DOBOOK_JPGENCODE_COMPLETE, testRndComplete, false, 0, true);
            dobookEncoder.encode(targetBitmap.bitmapData);
======================================================================
var scale:Number = 4;
            var myBMPD:BitmapData = new BitmapData( TestCanvas.width, TestCanvas.height);
            var myMatrix:Matrix = new Matrix( scale, 0, 0, scale );
            myBMPD.draw( TestCanvas, myMatrix );
            var bitmap : Bitmap = new Bitmap(myBMPD);
            var jpg:JPEGEncoder = new JPEGEncoder();
            var byteInfo:ByteArray = jpg.encode(myBMPD);

            var imageFile:File = new File(File.applicationDirectory.nativePath + "/Test.jpg");
            var fileStream:FileStream = new FileStream();
            fileStream.open(imageFile, FileMode.WRITE);
            while(fileStream.writeBytes(byteInfo, 0, byteInfo.length))
            {

            };
            fileStream.close();

Flex Scrolling with arrow button

Tuesday, June 7, 2011 Category : , 0

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" viewSourceURL="srcview/index.html">
    
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            
            [(source='Assets.swf', symbol='fwdMonthDown')]
            [] private var rightArrow:Class;
            
            [(source='Assets.swf', symbol='backMonthUp')]
            [] private var leftArrow:Class;
            
            [] private var dp:ArrayCollection = new ArrayCollection([
            {label:"11111111111"},
            {label:"22222222222"},
            {label:"33333333333"}
            ]);
            
            private function adjustSize():void {
                if(container.maxHorizontalScrollPosition > 0){
                    if(container.horizontalScrollPosition > container.maxHorizontalScrollPosition)
                        container.horizontalScrollPosition = container.maxHorizontalScrollPosition;
                    scrollLeftBtn.visible = true;
                    scrollRightBtn.visible = true;
                }else{
                    container.horizontalScrollPosition = 0;
                    scrollLeftBtn.visible = false;
                    scrollRightBtn.visible = false;
                }
            }
            
            private function scrollLeft(delta:int = 10):void {
                if(container.horizontalScrollPosition > 0)
                    container.horizontalScrollPosition -= delta;
            }
            
            private function scrollRight(delta:int = 10):void {
                if(container.horizontalScrollPosition < container.maxHorizontalScrollPosition)
                    container.horizontalScrollPosition += delta;
            }
            
            private function onMouseWheel(event:MouseEvent):void {
                if(event.delta > 0)
                    scrollLeft(20);
                else if(event.delta < 0)
                    scrollRight(20);
            }
            
            private function onAddItem():void {
                var i:int = dp.length+1;
                var o:Object = {label: String(i * 11111111111)};
                dp.addItem(o);
            }
            
            private function onRemoveItem():void {
                if(dp.length > 0)
                    dp.removeItemAt(dp.length-1);
            }
            
        ]]>
    </mx:Script>
    
    
    <mx:Box width="60%" id="parentContainer" backgroundColor="#ffcc00">
        
        <mx:HBox width="100%" horizontalGap="0" mouseWheel="onMouseWheel(event)" resize="adjustSize()"
            horizontalScrollPolicy="off">
            <mx:Button buttonDown="scrollLeft()" autoRepeat="true" id="scrollLeftBtn"
                includeInLayout="{scrollLeftBtn.visible}" visible="false"
                cornerRadius="0" icon="{leftArrow}" width="20" />
            <mx:HBox maxWidth="{parentContainer.width-scrollRightBtn.width-scrollLeftBtn.width}"
                horizontalScrollPolicy="off" id="container"
                horizontalGap="0">
                <mx:LinkBar dataProvider="{dp}" labelField="label" updateComplete="adjustSize()" />
            </mx:HBox>
            <mx:Button buttonDown="scrollRight()" autoRepeat="true" id="scrollRightBtn"
                includeInLayout="{scrollRightBtn.visible}" visible="false"
                cornerRadius="0" icon="{rightArrow}" width="20" />
        </mx:HBox>
        
    </mx:Box>
    <mx:Button label="add item" click="onAddItem()" />
    <mx:Button label="remove item" click="onRemoveItem()" />
    
</mx:Application>

Powered by Blogger.