麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開(kāi)發(fā) > Flex > 正文

flex 手寫在線簽名實(shí)現(xiàn)代碼第1/2頁(yè)

2024-09-12 17:51:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
在線手寫簽名分兩部份。第一部分是畫圖功能的實(shí)現(xiàn),第二部份是上傳圖片的功能(上傳到服務(wù)器或保存到本地)。
畫圖:畫圖比較簡(jiǎn)單,只要用到了graphics對(duì)像的幾個(gè)方法。當(dāng)鼠標(biāo)按下時(shí),調(diào)用graphics的beginFill和moveTo方法。同時(shí),還要把調(diào)用了lineTo的方法加入到鼠標(biāo)的MOUSE_MOVE事件中。代碼如下:
Actionscript代碼
復(fù)制代碼 代碼如下:

package com.humanmonth.home.component.page.signature
{
import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.LineScaleMode;
import flash.events.MouseEvent;
import mx.containers.Canvas;
import mx.core.UIComponent;
/**
* 實(shí)現(xiàn)手寫簽名的白板
* @author presses
*
*/
public class WriteArea extends Canvas
{
/**
*筆
*/
public var signature:UIComponent=new UIComponent();
/**
*顏色
*/
public var myColor:uint=0x000000 ;
/**
*線條粗細(xì)
*/
public var lineSize:int=1 ;
/**
*模式
*/
public var pattern:String="圓珠筆";
/**
*當(dāng)前的x座標(biāo)
*/
private var cX:Number;
/**
*當(dāng)前的y座標(biāo)
*/
private var cY:Number;
public function WriteArea()
{
this.addChild(signature);
this.addEventListener(MouseEvent.MOUSE_DOWN,beginDraw);
this.addEventListener(MouseEvent.MOUSE_UP,endDraw);
}
/**
*鼠標(biāo)壓下時(shí),開(kāi)始畫圖,并添加移動(dòng)鼠標(biāo)畫線的監(jiān)聽(tīng)器
*/
private function beginDraw(event:MouseEvent):void{
this.signature.graphics.lineStyle(lineSize,myColor,1 ,true,LineScaleMode.NONE,CapsStyle.ROUND,JointStyle.ROUND, 99 );
this.signature.graphics.beginFill(myColor);
this.cX=event.localX;
this.cY=event.localY;
this.signature.graphics.moveTo(this.cX,this.cY);
this.addEventListener(MouseEvent.MOUSE_MOVE,drawIng);
}
/**
* 鼠標(biāo)移動(dòng)時(shí),畫線
*/
private function drawIng(event:MouseEvent):void{
if(this.pattern=="圓珠筆"){
this.signature.graphics.moveTo(this.cX,this.cY);
}
this.signature.graphics.lineTo(event.localX,event.localY);
this.cX=event.localX;
this.cY=event.localY;
}
/**
* 結(jié)束畫圖
*/
private function endDraw(event:MouseEvent):void{
this.removeEventListener(MouseEvent.MOUSE_MOVE,drawIng);
}
}
}
package com.humanmonth.home.component.page.signature
{
    import flash.display.CapsStyle;
    import flash.display.JointStyle;
    import flash.display.LineScaleMode;
    import flash.events.MouseEvent;

    import mx.containers.Canvas;
    import mx.core.UIComponent;

    /**
     * 實(shí)現(xiàn)手寫簽名的白板
     * @author presses
     *
     */
    public class WriteArea extends Canvas
    {
        /**
         *筆
         */
        public var signature:UIComponent=new UIComponent();
        /**
         *顏色
         */
        public var myColor:uint=0x000000;
        /**
         *線條粗細(xì)
         */
        public var lineSize:int=1;
        /**
         *模式
         */
        public var pattern:String="圓珠筆";
        /**
         *當(dāng)前的x座標(biāo)
         */
        private var cX:Number;
        /**
         *當(dāng)前的y座標(biāo)
         */
        private var cY:Number;

        public function WriteArea()
        {
            this.addChild(signature);
            this.addEventListener(MouseEvent.MOUSE_DOWN,beginDraw);
            this.addEventListener(MouseEvent.MOUSE_UP,endDraw);
        }

        /**
         *鼠標(biāo)壓下時(shí),開(kāi)始畫圖,并添加移動(dòng)鼠標(biāo)畫線的監(jiān)聽(tīng)器
         */
        private function beginDraw(event:MouseEvent):void{
            this.signature.graphics.lineStyle(lineSize,myColor,1,true,LineScaleMode.NONE,CapsStyle.ROUND,JointStyle.ROUND,99);
            this.signature.graphics.beginFill(myColor);
            this.cX=event.localX;
            this.cY=event.localY;
            this.signature.graphics.moveTo(this.cX,this.cY);
            this.addEventListener(MouseEvent.MOUSE_MOVE,drawIng);
        }

        /**
         * 鼠標(biāo)移動(dòng)時(shí),畫線
         */
        private function drawIng(event:MouseEvent):void{
            if(this.pattern=="圓珠筆"){
                this.signature.graphics.moveTo(this.cX,this.cY);
            }
            this.signature.graphics.lineTo(event.localX,event.localY);
            this.cX=event.localX;
            this.cY=event.localY;
        }

        /**
         * 結(jié)束畫圖
         */
        private function endDraw(event:MouseEvent):void{
            this.removeEventListener(MouseEvent.MOUSE_MOVE,drawIng);
        }

    }
}

上傳簽名圖片(上傳到服務(wù)器或保存到本地):fp10(flash player)可以不經(jīng)服務(wù)器,直接把圖片保存到本地。但為了兼容fp9,這里的實(shí)現(xiàn)是先把圖片上傳到服務(wù)器,再調(diào)用下載功能。實(shí)現(xiàn)的思路是先把畫圖的組件轉(zhuǎn)化為BitmapData,然后再編碼成jpeg格式,并上傳到服務(wù)器。最后調(diào)用客戶端下載。這里要注意的一點(diǎn)是,fp10對(duì)下載的api作了限制,下載動(dòng)作只能由用戶觸發(fā)。代碼如下:
Actionscript代碼
復(fù)制代碼 代碼如下:

package com.humanmonth.home.component.page.signature.remote
{
import com.humanmonth.global.Config;
import flash.display.BitmapData;
import flash.events.Event;
import flash.net.FileReference;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import mx.controls.Alert;
import mx.graphics.codec.JPEGEncoder;
import mx.managers.CursorManager;
/**
* 圖片的上傳及下載
* @author presses
*
*/
public class Connector
{
private var file:FileReference;
private var myId:String;
public function Connector()
{
}
/**
* 保存圖片
*/
public function savePic(myData:BitmapData,fun:Function):void{
CursorManager.setBusyCursor();
var url:String=Config.picLink+"rea/pic.do?action=savePic&timestamp="+new Date().getTime();
var request:URLRequest = new URLRequest(url);
request.method=URLRequestMethod.POST;
request.contentType = "application/octet-stream";
request.data=new JPEGEncoder(80 ).encode(myData);
var loader:URLLoader = new URLLoader();
loader.load(request) ;
loader.addEventListener(Event.COMPLETE, fun) ;
loader.addEventListener(Event.COMPLETE,initMyId);
Alert.show("正在上傳圖片,等待數(shù)秒后,即可下載圖片");
}
private function initMyId(event:Event):void{
CursorManager.removeBusyCursor();
var loader:URLLoader=URLLoader(event.target);
this.myId=loader.data;
Alert.show("上傳圖片成功,現(xiàn)在可以點(diǎn)擊‘下載圖片'按鈕,保存圖片到本地。");
}
/**
* 下載圖片
*/
public function downloadFile(event:Event):void{
var url2:String=Config.picLink+"rea/pic.do?action=queryPicById&pid="+myId+"&timestamp="+new Date().getTime();
var req:URLRequest=new URLRequest(url2);
file=new FileReference();
file.download(req,"humanmonth.jpg");
}
}
}
package com.humanmonth.home.component.page.signature.remote
{
    import com.humanmonth.global.Config;

    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.net.FileReference;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;

    import mx.controls.Alert;
    import mx.graphics.codec.JPEGEncoder;
    import mx.managers.CursorManager;

    /**
     * 圖片的上傳及下載
     * @author presses
     *
     */
    public class Connector
    {
        private var file:FileReference;
        private var myId:String;
        public function Connector()
        {
        }

        /**
         * 保存圖片
         */
        public function savePic(myData:BitmapData,fun:Function):void{
         CursorManager.setBusyCursor();
            var url:String=Config.picLink+"rea/pic.do?action=savePic&timestamp="+new Date().getTime();
            var request:URLRequest = new URLRequest(url);             
            request.method=URLRequestMethod.POST;
             request.contentType = "application/octet-stream";
            request.data=new JPEGEncoder(80).encode(myData);
var loader:URLLoader = new URLLoader();
loader.load(request) ;
loader.addEventListener(Event.COMPLETE, fun) ;     
loader.addEventListener(Event.COMPLETE,initMyId);
Alert.show("正在上傳圖片,等待數(shù)秒后,即可下載圖片");        
        }

        private function initMyId(event:Event):void{
         CursorManager.removeBusyCursor();
            var loader:URLLoader=URLLoader(event.target);
            this.myId=loader.data;
            Alert.show("上傳圖片成功,現(xiàn)在可以點(diǎn)擊‘下載圖片'按鈕,保存圖片到本地。");

        }

        /**
         * 下載圖片
         */
        public function downloadFile(event:Event):void{
            var url2:String=Config.picLink+"rea/pic.do?action=queryPicById&pid="+myId+"&timestamp="+new Date().getTime();
            var req:URLRequest=new URLRequest(url2);
            file=new FileReference();
            file.download(req,"humanmonth.jpg");
        }
    }
}

Actionscript代碼
復(fù)制代碼 代碼如下:

package com.humanmonth.home.component.page.signature
{
import com.humanmonth.home.component.page.signature.remote.Connector;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.core.Application;
import mx.events.ColorPickerEvent;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.events.NumericStepperEvent;
/**
* 控制面版
* @author presses
*
*/
public class MyControlBarAs extends MyControlBar
{
public var writearea:WriteArea;
private var connector:Connector=new Connector();
public function MyControlBarAs()
{
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE,myInit);
}
private function myInit(event:Event):void{
this.writearea=Application.application.signature.writearea;
this.reset.addEventListener(MouseEvent.CLICK,cleanArea);
this.size.addEventListener(NumericStepperEvent.CHANGE,setLineSize);
this.color.addEventListener(ColorPickerEvent.CHANGE,setColor);
this.pattern.addEventListener(ListEvent.CHANGE,setPattern);
this.savePic.addEventListener(MouseEvent.CLICK,savePicture);
this.downloadPic.addEventListener(MouseEvent.CLICK,connector.downloadFile)
}
/**
* 保存圖片
*/
private function savePicture(event:Event):void{
var myData:BitmapData=new BitmapData(this.writearea.width,this.writearea.height);
myData.draw(this.writearea);
connector.savePic(myData,enableDownload);
}
private function enableDownload(event:Event):void{
this.downloadPic.enabled=true;
}
/**
* 設(shè)置模式
*/
private function setPattern(event:Event):void{
this.writearea.pattern=String(this.pattern.value);
}
/**
* 清空寫字區(qū)
*/
private function cleanArea(event:Event):void{
this.writearea.signature.graphics.clear();
}
/**
* 設(shè)置線條粗細(xì)
*/
public function setLineSize(event:Event):void{
this.writearea.lineSize=this.size.value;
}
/**
* 設(shè)置顏色
*/
public function setColor(event:Event):void{
this.writearea.myColor=uint(this.color.value);
}
}
}
package com.humanmonth.home.component.page.signature
{
    import com.humanmonth.home.component.page.signature.remote.Connector;

    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.events.MouseEvent;

    import mx.core.Application;
    import mx.events.ColorPickerEvent;
    import mx.events.FlexEvent;
    import mx.events.ListEvent;
    import mx.events.NumericStepperEvent;

    /**
     * 控制面版
     * @author presses
     *
     */
    public class MyControlBarAs extends MyControlBar
    {
        public var writearea:WriteArea;
        private var connector:Connector=new Connector();
        public function MyControlBarAs()
        {
            super();
            this.addEventListener(FlexEvent.CREATION_COMPLETE,myInit);
        }

        private function myInit(event:Event):void{
            this.writearea=Application.application.signature.writearea;
            this.reset.addEventListener(MouseEvent.CLICK,cleanArea);
            this.size.addEventListener(NumericStepperEvent.CHANGE,setLineSize);
            this.color.addEventListener(ColorPickerEvent.CHANGE,setColor);
            this.pattern.addEventListener(ListEvent.CHANGE,setPattern);
            this.savePic.addEventListener(MouseEvent.CLICK,savePicture);
            this.downloadPic.addEventListener(MouseEvent.CLICK,connector.downloadFile)
        }
        /**
         * 保存圖片
         */
        private function savePicture(event:Event):void{
            var myData:BitmapData=new BitmapData(this.writearea.width,this.writearea.height);
            myData.draw(this.writearea);
            connector.savePic(myData,enableDownload);
        }

        private function enableDownload(event:Event):void{
            this.downloadPic.enabled=true;
        }
        /**
         * 設(shè)置模式
         */
        private function setPattern(event:Event):void{
            this.writearea.pattern=String(this.pattern.value);
        }
        /**
         * 清空寫字區(qū)
         */
        private function cleanArea(event:Event):void{
            this.writearea.signature.graphics.clear();
        }

        /**
         * 設(shè)置線條粗細(xì)
         */
        public function setLineSize(event:Event):void{
            this.writearea.lineSize=this.size.value;
        }

        /**
         * 設(shè)置顏色
         */
        public function setColor(event:Event):void{
            this.writearea.myColor=uint(this.color.value);
        }

        
    }
}

到這里為止,功能已經(jīng)實(shí)現(xiàn)了。但效果不太好。主要是簽名時(shí),筆畫不圓滑,在flex 的api中,好像找不到在flash中設(shè)置圓滑的功能。
效果圖:http://rea.humanmonth.com/
12下一頁(yè)閱讀全文
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 在线影院av | 久精品久久 | 91成人免费视频 | 中文黄色一级片 | 中文字幕视频在线播放 | 国产成人网 | 国产免费一区二区三区最新不卡 | 国产精品视频在 | 国产精品区一区二区三区 | 91情侣偷在线精品国产 | 毛片在哪看 | 日本娇小videos高潮 | 国产一区二区三区撒尿在线 | 久久成人综合网 | 成人三级黄色片 | 色柚视频网站ww色 | 国产在线观看91精品 | 欧美精品一区二区三区久久久 | 99在线热播精品免费 | 久久精品日产高清版的功能介绍 | 成人在线视频精品 | 91成人免费电影 | 337p粉嫩大胆噜噜噜亚瑟影院 | 久久福利精品 | 在火车上摸两乳爽的大叫 | 亚洲福利在线观看视频 | 国产午夜精品久久久久 | 欧美极品免费 | a网站在线 | 一级黄色a视频 | 视频一区二区三区在线播放 | 九九热国产视频 | 日本欧美一区二区三区在线观看 | 精品一区二区三区在线观看视频 | av国产片| 中文在线观看www | av电影在线观看网站 | 国产精品久久久久久久亚洲按摩 | 成年人高清视频在线观看 | japan护士性xxxⅹhd | 视频h在线 |