actionScript 3.0 图片裁剪及旋转
2024-11-09
来源:个人技术集锦
代码一:
- package
- {
- import com.wdxc.ImageCut;
- import com.wdxc.ImageRotation;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- import flash.events.* ;
- import flash.display.*;
- import flash.geom.* ;
- import flash.net.*;
- import flash.text.TextField;
- import flash.utils.ByteArray;
- import com.wdxc.util.* ;
- import fl.containers.ScrollPane;
- import flash.display.Shape;
- import fl.events.ScrollEvent;
- import flash.external.ExternalInterface;
- import flash.system.Security;
- import flash.utils.Timer;
- import flash.events.TimerEvent ;
- import com.wdxc.* ;
-
-
-
-
- public class Main extends MovieClip
- {
-
- private var _bitmap:Bitmap ;
-
- private var _progressbar:TextField ;
-
- private var picname:String ;
-
- public var _imageCut:ImageCut = new ImageCut() ;
-
-
- public static var SCENE:MovieClip ;
-
- public static var _handerState:int = 0 ;
-
-
- public var pelsHint:TextField = new TextField();
-
- public var photoid :String = "0";
-
- public var ir:ImageRotation ;
-
-
-
- public var picScale :Number = 2 ;
-
-
- public function Main():void {
- flash.system.Security.allowDomain("*");
-
- photoid = this.loaderInfo.parameters['photoid'];
-
-
-
- SCENE = this;
-
- menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, this._imageCut.startCutPic);
-
- menu_mc.rotate_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotationHandler) ;
-
- checkAvailable();
-
- this.addPelsHint();
- startLoadPic();
- }
-
-
- private function addPelsHint():void {
- this.addChild(pelsHint);
-
- pelsHint.x = 150 ;
- pelsHint.y = 0 ;
- pelsHint.height = 20 ;
- this.pelsHint.width = 350 ;
- pelsHint.textColor =0xFF0000;
- }
-
- public function setPelsHint(p:Number,hint:String):void {
-
- this.pelsHint.text = "像素:" + String(p) + " " + hint ;
-
- }
-
- private function rotationHandler(e:MouseEvent):void {
- ir = new ImageRotation() ;
- ir.x = menu_mc.x ;
- ir.y = menu_mc.y ;
- this.stage.addChild(ir);
- }
-
-
-
-
-
-
-
-
-
-
-
- public function set bitmap(bp:Bitmap):void {
- this._bitmap = bp ;
- }
-
- public function get bitmap():Bitmap {
- return this._bitmap ;
- }
-
- public function startLoadPic():void {
-
- var param:URLVariables = new URLVariables() ;
- var url:String = "/photo/LoaderPhotoServlet";
-
-
- param.random = Math.floor(Math.random() * 1000);
- param.photoid = photoid ;
-
-
-
-
- var request:URLRequest = new URLRequest(url);
- request.data = param ;
- var loader :Loader = new Loader();
- loader.load(request);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, picLoadCompleteHandler);
- }
-
-
- private function picLoadCompleteHandler(e:Event):void {
-
-
- if (Main._handerState == 1||Main._handerState==2) {
- this.delVagueBg();
- delLoadingBar();
- calljs();
- }
- Main._handerState = 0 ;
-
-
-
-
- this._bitmap = new Bitmap() ;
-
- var loader:Loader = e.target.loader as Loader;
-
- var _bitmapdata:BitmapData = new BitmapData(loader.width, loader.height);
- _bitmapdata.draw(loader);
-
-
-
-
-
-
-
-
-
- this._bitmap.bitmapData = _bitmapdata;
- this.addChild(_bitmap);
- this.reset() ;
-
- this._imageCut.bitmap = this._bitmap ;
- this.addChild(this._imageCut);
-
- e.currentTarget.removeEventListener(Event.COMPLETE, picLoadCompleteHandler);
-
- }
-
-
-
-
- public function removeBitmap():void {
-
- this.removeChild(_bitmap);
- }
- public function reset():void {
- this._bitmap.x = (Constant.LEFT_AREA_WIDTH-_bitmap.width)/2 ;
- this._bitmap.y = (Constant.SCRENE_HEIGHT - _bitmap.height) / 2 ;
- }
-
- public function checkAvailable():void {
- if (ExternalInterface.available){
- try {
- ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
- if (checkJavaScriptReady()) {
-
- } else {
-
-
- var readyTimer:Timer = new Timer(100, 0);
- readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
- readyTimer.start();
- }
- }catch (error:SecurityError) {
-
-
- }catch (error:Error) {
-
-
- }
- }else{
-
- }
-
- }
-
- private function timerHandler(event:TimerEvent):void {
-
- var isReady:Boolean = checkJavaScriptReady();
-
- if (isReady) {
-
- Timer(event.target).stop();
- }
- }
-
-
- private function receivedFromJavaScript(pid:String, plength:Number):void {
-
-
- this.photoid = pid ;
-
-
- this.picScale = plength/500 ;
-
-
-
- removeBitmap();
-
- if (Main._handerState == 5) {
- _imageCut.removeCutMenu();
-
- }
-
- else if (Main._handerState == 6) {
- _imageCut.removeCutMenu();
- _imageCut.removeHint();
- } else if (Main._handerState == 10) {
- ir.remove();
- }
-
-
-
-
-
- startLoadPic();
- }
- private function checkJavaScriptReady():Boolean {
- var isReady:Boolean = ExternalInterface.call("isReady");
- return isReady;
- }
-
- public function calljs():void {
- if (ExternalInterface.available) {
- ExternalInterface.call("rationAndCropComplete", "123");
- }
- }
-
-
- public var _vaguebg:Sprite ;
- public function addVagueBg():void {
- _vaguebg = new Sprite() ;
- _vaguebg.graphics.beginFill(0x000000);
- _vaguebg.graphics.drawRect(0, 0, 770, 530);
- _vaguebg.graphics.endFill();
- _vaguebg.alpha = 0.5;
-
- this.addChild(_vaguebg);
-
- }
- public function delVagueBg():void {
- this.removeChild(_vaguebg);
- }
-
-
- public var loadingbar:Sprite ;
- public function addLoadingBar():void {
- loadingbar = new LoadingBar();
- this.addChild(loadingbar) ;
- loadingbar.x = 200 ;
- loadingbar.y = 150 ;
- }
-
- public function delLoadingBar():void {
- this.removeChild(loadingbar);
- }
- }
- }
代码二:
- package com.wdxc {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.events.* ;
- import flash.display.* ;
- import flash.geom.Matrix;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.printing.PrintJob;
- import flash.ui.Mouse ;
-
- import flash.utils.* ;
- import com.wdxc.Constant ;
- import fl.controls.* ;
-
-
- public class ImageCut extends Sprite{
-
-
- private var _bitmap:Bitmap ;
-
- private var _rect:Sprite ;
-
- private var _cutMenu:CutMenu ;
-
- private var _cursor1:Sprite ;
-
- private var _cursor2:Sprite ;
-
- private var _mouseInfo:MouseInfo = new MouseInfo() ;
-
- private var _tempObj:Object = new Object() ;
-
-
- private var _tempBitmapData:BitmapData ;
-
- private var bg1:Sprite ;
-
-
- private var _vaguebg:Sprite ;
-
-
- private var _cutScale:Number = 0 ;
-
-
- public var cutscaleFlag:int = Constant.HORIZONTAL;
-
- public var minPels:Number = 800 * 600;
-
- private var scaleInfo:String = "0";
-
- public function ImageCut() {
- }
-
-
- private function createCursor():void {
- _cursor1 = new Cursor1() ;
- _cursor1.x = mouseX ;
- _cursor1.y = mouseY ;
- _cursor1.visible = false ;
-
- _cursor2 = new Cursor2() ;
- _cursor2.x = mouseX ;
- _cursor2.y = mouseY ;
- _cursor2.visible = false ;
-
- this.addChild(_cursor1);
- this.addChild(_cursor2) ;
- }
-
-
-
- private function createCutMenu():void {
-
-
- Main.SCENE.pelsHint.visible = true ;
-
- _cutMenu = new CutMenu();
- _cutMenu.x = Main.SCENE.menu_mc.x ;
- _cutMenu.y = Main.SCENE.menu_mc.y ;
-
- this.addChild(_cutMenu);
- _cutMenu.cutok_btn.addEventListener(MouseEvent.CLICK, saveHint) ;
- _cutMenu.cutcancle_btn.addEventListener(MouseEvent.CLICK, cutCancle) ;
- _cutMenu.preview_btn.addEventListener(MouseEvent.CLICK, cutPreview) ;
-
- _cutMenu.rd5_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd6_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd62_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd7_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd8_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd10_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd12_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd16_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd18_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd20_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd24_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd30_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd40_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd0_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- }
-
-
-
- private function createCutRect():void {
- _rect = new Sprite();
- _rect.x = _bitmap.x ;
- _rect.y = _bitmap.y ;
-
- _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
- _rect.graphics.beginFill(0xCCFF00,0);
- _rect.graphics.drawRect(0,0,_bitmap.width-20,_bitmap.height-20);
- _rect.graphics.endFill();
- this.addChild(_rect);
- }
-
- public function set bitmap(bp:Bitmap):void {
- this._bitmap = bp ;
- }
- public function get bitmap():Bitmap {
- return this._bitmap ;
- }
-
-
-
- public function startCutPic(e:MouseEvent):void
- {
-
-
- if ( _bitmap.height > _bitmap.width) {
-
- this.cutscaleFlag = Constant.VERTICAL ;
- } else {
- this.cutscaleFlag = Constant.HORIZONTAL ;
- }
-
- Main._handerState = 5;
-
- this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ;
- this.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler) ;
- this.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler) ;
- this.createCutMenu() ;
- this.createCutRect() ;
- this.createCursor() ;
-
-
- }
- private function changeHandler(e:Event):void {
-
- trace(123);
- }
-
-
- private function scaleSelectHandler(e:MouseEvent):void {
- var rb:RadioButton = e.target as RadioButton;
-
-
- switch(rb.value) {
- case "5" :
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 3.5):(3.5 / 5) ;
- scaleInfo = "5 : 3.5";
- this.minPels = 800 * 600 ;
- break ;
- case "6" :
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(3 / 2):(2 / 3) ;
- scaleInfo = "3 : 2";
- this.minPels = 1024 * 768 ;
- break ;
- case "62":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
- scaleInfo = "4 : 3";
- this.minPels = 1024 * 768 ;
- break ;
- case "7" :
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(7 / 5):(5 / 7) ;
- scaleInfo = "7 : 5";
- this.minPels = 1280 * 960 ;
- break ;
- case "8" :
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
- scaleInfo = "4 : 3";
- this.minPels = 1280 * 960 ;
- break ;
- case "10":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
- scaleInfo = "5 : 4";
- this.minPels = 1600 * 1200 ;
- break ;
- case "12":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(6 / 5):(5 / 6) ;
- scaleInfo = "6 : 5";
- this.minPels = 1600 * 1200 ;
- break ;
- case "16":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "4 : 3";
- break ;
- case "18":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(3 / 2):(2 / 3) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "3 : 2";
- break ;
- case "20":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "5 : 4";
- break ;
- case "24":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(6 / 5):(5 / 6) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "6 : 5";
- break ;
- case "30":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "5 : 4";
- break ;
- case "40":
- this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
- this.minPels = 2048 * 1953 ;
- scaleInfo = "4 : 3";
- break
- case "0":
- this._cutScale = 0;
- this.minPels = 800 * 600 ;
- scaleInfo = "0";
- break ;
- }
-
- this._rect.graphics.clear();
- this._rect.x = _bitmap.x ;
- this._rect.y = _bitmap.y ;
- _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
- _rect.graphics.beginFill(0xCCFF00, 0);
-
- if (this._cutScale == 0) {
-
- _rect.graphics.drawRect(0, 0, _bitmap.width-20,_bitmap.height-20);
- }else {
- var w = _bitmap.width ;
- var h = w / this._cutScale ;
-
-
- if (h < _bitmap.height) {
- _rect.graphics.drawRect(0,0,w,h);
- }else {
- _rect.graphics.drawRect(0,0,_bitmap.height*this._cutScale,_bitmap.height);
- }
- }
-
- _rect.graphics.endFill();
-
- }
-
- private function cutCancle(e:MouseEvent):void {
-
- Main._handerState = 0 ;
- removeCutMenu();
- }
-
-
-
- private function cutApplication(e:MouseEvent):void {
-
-
- Main.SCENE.addLoadingBar();
-
- var server :ImageService = new ImageService();
- server.photoid = Main.SCENE.photoid ;
-
- var tempx:Number = Math.round(_rect.x - this._bitmap.x);
- var tempy:Number = Math.round(_rect.y - this._bitmap.y) ;
-
- server.submitCut(tempx, tempy, Math.round(_rect.width), Math.round(_rect.height),this.scaleInfo);
-
- this.removeCutMenu();
- _cutSaveHint.removeEventListener(MouseEvent.CLICK, removeHintHandler);
- _cutSaveHint.removeEventListener(MouseEvent.CLICK, cutApplication);
-
- this.stage.removeChild(_cutSaveHint);
-
- Main._handerState = 1 ;
-
-
- var ml = _rect.width > _rect.height?_rect.width:_rect.height ;
-
-
- Main.SCENE.picScale = Main.SCENE.picScale * ml/500 ;
-
-
-
- }
-
- public var _cutSaveHint:CutSaveHint ;
-
-
-
- private function saveHint(e:MouseEvent):void {
-
-
- Main._handerState = 6 ;
-
- Main.SCENE.addVagueBg();
-
-
- _cutSaveHint = new CutSaveHint();
-
- _cutSaveHint.x = (Constant.LEFT_AREA_WIDTH-_cutSaveHint.width)/2 ;
- _cutSaveHint.y = 200 ;
-
- this.stage.addChild(_cutSaveHint);
-
- _cutSaveHint.ok_btn.addEventListener(MouseEvent.CLICK, cutApplication);
- _cutSaveHint.cancle1_btn.addEventListener(MouseEvent.CLICK,removeHintHandler);
-
-
- this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ;
- }
-
- private function removeHintHandler(e:MouseEvent):void {
-
- removeHint();
-
- }
-
- public function removeHint():void {
-
-
- Main._handerState = 5 ;
-
-
- _cutSaveHint.removeEventListener(MouseEvent.CLICK, removeHintHandler);
- _cutSaveHint.removeEventListener(MouseEvent.CLICK, cutApplication);
- this.stage.removeChild(_cutSaveHint);
-
-
-
- this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ;
-
- Main.SCENE.delVagueBg();
- }
-
-
-
- private function cutPreview(e:MouseEvent):void {
-
-
- bg1 = new Sprite() ;
- bg1.graphics.beginFill(0x000000);
- bg1.graphics.drawRect(0, 0, 770, 530);
- bg1.graphics.endFill();
- bg1.alpha = 0;
- bg1.x = Constant.LEFT_AREA_WIDTH+Constant.MIDDLE_AREA_WIDTH ;
- this.addChild(bg1);
-
-
- _tempBitmapData = this._bitmap.bitmapData.clone() ;
-
-
-
- var cutbitmapdata:BitmapData = new BitmapData(Math.floor(_rect.width),Math.ceil(_rect.height)) ;
-
-
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -Math.floor(_rect.x-_bitmap.x), -Math.floor(_rect.y-_bitmap.y));
- cutbitmapdata.draw(this._bitmap.bitmapData, matrix);
-
-
- this._bitmap.bitmapData.dispose() ;
- this._bitmap.bitmapData = cutbitmapdata ;
- this._rect.visible = false ;
-
- Main.SCENE.reset();
- setTimeout(previewCompletehandler, 2000) ;
- }
-
- private function previewCompletehandler():void {
- this._bitmap.bitmapData.dispose();
- this._bitmap.bitmapData = this._tempBitmapData ;
- Main.SCENE.reset();
- this._rect.visible = true ;
- this.removeChild(bg1) ;
- }
-
-
-
- public function removeCutMenu():void {
-
-
- Main._handerState = 0 ;
-
-
- Main.SCENE.pelsHint.visible = false ;
-
- _cutMenu.cutok_btn.removeEventListener(MouseEvent.MOUSE_DOWN, cutApplication);
- _cutMenu.cutcancle_btn.removeEventListener(MouseEvent.MOUSE_DOWN, cutCancle) ;
-
-
- _cutMenu.rd5_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd6_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd62_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd7_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd8_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd10_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd12_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd16_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd18_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd20_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd24_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd30_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd40_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- _cutMenu.rd0_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
- this._cutScale = 0 ;
-
-
- this.stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler) ;
- this.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler) ;
- this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ;
-
- this.removeChild(_cutMenu) ;
- this.removeChild(_rect) ;
- this.removeChild(_cursor1);
- this.removeChild(_cursor2) ;
- }
-
-
-
- private function mouseDownHandler(e:MouseEvent):void {
-
-
- this._tempObj.width = _rect.width-Constant.BORDER ;
- this._tempObj.height = _rect.height-Constant.BORDER ;
- this._tempObj.x = _rect.x ;
- this._tempObj.y = _rect .y ;
-
-
- this._mouseInfo.state = Constant.MOUSE_DOWN ;
- }
- private function mouseUpHandler(e:MouseEvent):void {
- _rect.stopDrag();
-
- this._mouseInfo.state = Constant.MOUSE_UP ;
- }
-
-
- private function mouseMoveHandler(e:MouseEvent):void {
- Mouse.hide() ;
- this._cursor1.visible = false ;
- this._cursor2.visible = false ;
-
-
- if (_mouseInfo.isStartLeftDrag()) {
- this.resetCursorPosition(Constant.CURSOR_HORIZONTAL) ;
- this.repaint(Constant.LEFT);
- }
-
- else if(_mouseInfo.isStartRightDrag()) {
- this.resetCursorPosition(Constant.CURSOR_HORIZONTAL);
- this.repaint(Constant.RIGHT);
- }
-
- else if(_mouseInfo.isStartUpDrag()) {
- this.resetCursorPosition(Constant.CURSOR_VERTICAL);
- this.repaint(Constant.UP);
- }
-
- else if(_mouseInfo.isStartDownDrag()) {
- this.resetCursorPosition(Constant.CURSOR_VERTICAL);
- this.repaint(Constant.DOWN);
- }
-
- else if (_mouseInfo.isStartMiddleDrag()) {
- this.resetCursorPosition(Constant.CURSOR_MOVE);
- this.dragHandler();
- }
-
- else if (_mouseInfo.isStratLeftUPDrag()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT) ;
- this.repaint(Constant.LEFT_UP) ;
- }
-
- else if (_mouseInfo.isStratLeftDownDrag()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT) ;
- this.repaint(Constant.LEFT_DOWN) ;
- }
-
- else if (_mouseInfo.isStratRightUPDrag()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT) ;
- this.repaint(Constant.RIGHT_UP) ;
- }
-
- else if (_mouseInfo.isStratRightDownDrag()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT) ;
- this.repaint(Constant.RIGHT_DOWN) ;
- }
-
- else if (isLeftUpAngle()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT);
- this._mouseInfo.position = Constant.LEFT_UP ;
-
- }
-
- else if (isLeftDownAngle()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT);
- this._mouseInfo.position = Constant.LEFT_DOWN ;
-
- }
-
- else if (isRightUpAngle()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT);
- this._mouseInfo.position = Constant.RIGHT_UP ;
-
- }
-
- else if (isRightDownAngle()) {
- this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT);
- this._mouseInfo.position = Constant.RIGHT_DOWN ;
-
- }
-
-
- else if (isLeftEdge()) {
- this.resetCursorPosition(Constant.CURSOR_HORIZONTAL);
- this._mouseInfo.position = Constant.LEFT ;
-
- }
-
- else if (isRightEdge()) {
- this.resetCursorPosition(Constant.CURSOR_HORIZONTAL);
- this._mouseInfo.position = Constant.RIGHT ;
- }
-
- else if (isUpEdge()) {
- this.resetCursorPosition(Constant.CURSOR_VERTICAL);
- this._mouseInfo.position = Constant.UP ;
- }
-
- else if (isDownEdge()) {
- this.resetCursorPosition(Constant.CURSOR_VERTICAL);
- this._mouseInfo.position = Constant.DOWN ;
- }
-
- else if (this.isInCutRect()) {
- this.resetCursorPosition(Constant.CURSOR_MOVE);
- this._mouseInfo.position = Constant.MIDDLE ;
- }
- else {
- Mouse.show () ;
- }
- e.updateAfterEvent();
-
-
-
- this.pelsHint();
-
- }
-
- private function pelsHint():void {
- var p = _rect.width * _rect.height * Main.SCENE.picScale * Main.SCENE.picScale ;
- p = Math.round(p);
- if ( p < this.minPels) {
- Main.SCENE.setPelsHint(p,"像素太低,继续裁剪将会影响照片的冲印质量。");
- }else {
- Main.SCENE.setPelsHint(p,"");
- }
-
- }
-
-
- private function repaint(state:uint):void {
- this._rect.graphics.clear() ;
- _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
- _rect.graphics.beginFill(0xCCFF00, 0);
-
-
- switch(state) {
- case Constant.LEFT:
- this.leftDragHandler() ;
- break;
- case Constant.RIGHT:
- this.rightDragHandler();
- break ;
- case Constant.UP:
- this.upDragHandler();
- break ;
- case Constant.DOWN:
-
- downDragHandler();
- break;
- case Constant.LEFT_UP:
- this.leftUpDragHandler() ;
- break;
- case Constant.LEFT_DOWN:
-
- this.leftDownDragHandler();
- break;
- case Constant.RIGHT_UP:
-
- this.rightUpDragHandler();
- break;
- case Constant.RIGHT_DOWN:
-
- this.rightDownDragHandler();
- break;
- }
- _rect.graphics.endFill();
- }
-
-
- private function leftDragHandler():void {
- var w = 0 ;
- var h = 0;
- if(this._cutScale!=0) {
-
- _rect.x = mouseX < _bitmap.x?_bitmap.x:mouseX ;
- _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;
- w = _tempObj.width + _tempObj.x - _rect.x ;
- h = w / this._cutScale ;
-
- var h2 = this._bitmap.height+this._bitmap.y - this._tempObj.y ;
- if(h>=h2){
- _rect.x = this._tempObj.x + this._tempObj.width -h2*this._cutScale;
- w = _tempObj.width + _tempObj.x - _rect.x ;
- _rect.graphics.drawRect(0, 0, w, h2 );
- }
- else {
- _rect.graphics.drawRect(0, 0, w , h );
- }
-
- }
- else {
-
- _rect.x = mouseX < _bitmap.x?_bitmap.x:mouseX ;
- _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;
- _rect.graphics.drawRect(0, 0, _tempObj.width + _tempObj.x - _rect.x, _tempObj.height);
-
- }
- }
-
- private function rightDragHandler():void {
- var w:Number = 0 ;
- var h:Number = 0 ;
- if (this._cutScale != 0) {
-
- w = mouseX > (w = (_bitmap.x + _bitmap.width))?w:mouseX ;
- w = w <= this._tempObj.x?_tempObj.x:w ;
-
-
- w = w -this._tempObj.x ;
- h = w/ this._cutScale ;
- _rect.y = _tempObj.height + _tempObj.y - h;
-
- if (_rect.y < _bitmap.y) {
- h = _tempObj.height + _tempObj.y -_bitmap.y ;
- _rect.y = _bitmap.y ;
- w = h * this._cutScale ;
-
-
-
-
- }
-
-
- _rect.graphics.drawRect(0, 0, w,h);
-
- }
- else {
-
- w = mouseX > (w = (_bitmap.x + _bitmap.width))?w:mouseX ;
- w = w <= this._tempObj.x?_tempObj.x:w ;
- _rect.graphics.drawRect(0, 0, w -this._tempObj.x, _tempObj.height);
- }
-
- }
-
-
-
- private function upDragHandler():void {
-
- if (this._cutScale != 0) {
-
- _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;
- _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;
-
- var h = _tempObj.height + _tempObj.y-_rect.y ;
- var w = h * this._cutScale ;
-
- _rect.x = _tempObj.x + _tempObj.width - w ;
-
-
- if (_rect.x < _bitmap.x) {
- w = _tempObj.x + _tempObj.width - _bitmap.x ;
- _rect.x = _bitmap.x ;
-
- h = w / this._cutScale ;
-
- _rect.y = _tempObj.y + _tempObj.height - h ;
- }
-
- _rect.graphics.drawRect(0, 0,w,h);
-
- }else {
-
- _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;
- _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;
- _rect.graphics.drawRect(0, 0, _tempObj.width,_tempObj.height+_tempObj.y-_rect.y);
- }
- }
-
-
-
-
- private function downDragHandler():void {
- var h = 0 ;
- var w = 0;
- if (this._cutScale != 0) {
- h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
- h = h <= this._tempObj.y?_tempObj.y:h ;
-
- h = h - _tempObj.y ;
- w = h * this._cutScale ;
-
- if ((w + _tempObj.x) >= (_bitmap.width+_bitmap.x)) {
- w = _bitmap.x + _bitmap.width - _rect.x ;
- h = w / this._cutScale ;
-
- }
- _rect.graphics.drawRect(0, 0, w, h);
- }else {
- h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
- h = h <= this._tempObj.y?_tempObj.y:h ;
- _rect.graphics.drawRect(0, 0, _tempObj.width, h-_tempObj.y);
- }
- }
-
-
- private function leftUpDragHandler():void {
-
- if (this._cutScale != 0) {
- this.upDragHandler();
- }else {
-
- _rect.x = mouseX <= _bitmap.x?_bitmap.x:mouseX ;
- _rect.y = (mouseY <= _bitmap.y)?_bitmap.y:mouseY;
-
- var w = _tempObj.width + _tempObj.x ;
- var h = _tempObj.height + _tempObj.y ;
- _rect.x = _rect.x >= (w)?(w):_rect.x ;
- _rect.y = _rect.y >=(h)?(h): _rect.y ;
- _rect.graphics.drawRect(0, 0, w-_rect.x,h-_rect.y);
- }
- }
-
-
- private function leftDownDragHandler():void {
- if (this._cutScale != 0) {
- this.leftDragHandler();
- }else {
- _rect.x = mouseX <= _bitmap.x?_bitmap.x:mouseX ;
- _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;
- var h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
- h = h <= this._tempObj.y?_tempObj.y:h ;
- _rect.graphics.drawRect(0, 0, _tempObj.width + _tempObj.x - _rect.x,h-_tempObj.y);
- }
- }
-
- private function rightDownDragHandler():void {
- if (this._cutScale != 0) {
- this.downDragHandler();
- }else {
- var w = mouseY > (w = (_bitmap.y + _bitmap.height))?w:mouseY ;
- w = w <= this._tempObj.y?_tempObj.y:w ;
- var h = mouseX > (h = (_bitmap.x + _bitmap.width))?h:mouseX ;
- h = h <= this._tempObj.x?_tempObj.x:h
- _rect.graphics.drawRect(0, 0, h -this._tempObj.x, w-_tempObj.y);
- }
- }
-
- private function rightUpDragHandler():void {
- if (this._cutScale != 0) {
- this.rightDragHandler();
- }else {
- _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;
- _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;
- var h = mouseX > (h = (_bitmap.x + _bitmap.width))?h:mouseX ;
- h = h <= this._tempObj.x?_tempObj.x:h
- _rect.graphics.drawRect(0, 0, h -this._tempObj.x,_tempObj.height+_tempObj.y-_rect.y);
-
- }
- }
-
-
- private function resetCursorPosition(cursor:uint):void {
-
- if (cursor == Constant.CURSOR_MOVE) {
- this._cursor1.x = mouseX ;
- this._cursor1.y = mouseY ;
- this._cursor1.visible = true ;
- return ;
- }
- this._cursor2.x = mouseX ;
- this._cursor2.y = mouseY ;
- this._cursor2.visible = true ;
- switch(cursor) {
- case Constant.CURSOR_HORIZONTAL:
- _cursor2.rotation = 0 ;
- break ;
- case Constant.CURSOR_VERTICAL:
- _cursor2.rotation = 90 ;
- break ;
- case Constant.CURSOR_DIAGONAL_LEFT:
- _cursor2.rotation = 45 ;
- break ;
- case Constant.CURSOR_DIAGONAL_RIGHT:
- _cursor2.rotation = 135 ;
- break ;
- }
- }
-
-
-
- private function dragHandler():void {
-
- var _rectangle:Rectangle = new Rectangle();
- _rectangle.x = _bitmap.x ;
- _rectangle.y = _bitmap.y ;
- _rectangle.width = this._bitmap.width-_rect.width ;
- _rectangle.height = this._bitmap.height-_rect.height ;
- _rect.startDrag(false, _rectangle);
- }
-
-
-
- private function isLeftEdge():Boolean {
-
-
- if (mouseX>=(this._rect.x - Constant.ACTIVERANGE) &&
- mouseX<=(this._rect.x + Constant.ACTIVERANGE) &&
- mouseY>this._rect.y &&
- mouseY<(this._rect.y +this._rect.height)) {
- return true ;
- }
- return false ;
- }
-
-
-
- private function isRightEdge():Boolean {
- if (mouseX>=(this._rect.x + this._rect.width - Constant.ACTIVERANGE) &&
- mouseX<=(this._rect.x+this._rect.width + Constant.ACTIVERANGE) &
- mouseY>this._rect.y&&
- mouseY<(this._rect.y+this._rect.height)) {
- return true ;
- }
- return false ;
- }
-
-
-
- private function isUpEdge():Boolean {
- if (mouseX > this._rect.x && mouseX < (this._rect.x + _rect.width) &
- mouseY > (_rect.y - Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
- private function isDownEdge():Boolean {
- if (mouseX > this._rect.x && mouseX < (this._rect.x + _rect.width) &
- mouseY > (_rect.y + _rect.height - Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
- private function isLeftUpAngle():Boolean {
- if (mouseX > (this._rect.x-Constant.ACTIVERANGE) && mouseX < (this._rect.x +Constant.ACTIVERANGE) &
- mouseY > (_rect.y - Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
- private function isLeftDownAngle():Boolean {
- if (mouseX > (this._rect.x-Constant.ACTIVERANGE) && mouseX < (this._rect.x +Constant.ACTIVERANGE) &
- mouseY > (_rect.y+_rect.height - Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
- private function isRightUpAngle():Boolean {
- if (mouseX > (this._rect.x + _rect.width - Constant.ACTIVERANGE) &&
- mouseX < (this._rect.x+_rect.width +Constant.ACTIVERANGE) &
- mouseY > (_rect.y- Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
- private function isRightDownAngle():Boolean {
- if (mouseX > (this._rect.x + _rect.width - Constant.ACTIVERANGE) &&
- mouseX < (this._rect.x+_rect.width +Constant.ACTIVERANGE) &
- mouseY > (_rect.y+_rect.height- Constant.ACTIVERANGE) &&
- mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
-
-
-
- private function isInCutRect():Boolean {
- if (mouseX>(this._rect.x + Constant.ACTIVERANGE) &&
- mouseX<(this._rect.x + this._rect.width - Constant.ACTIVERANGE) &
- mouseY>(this._rect.y + Constant.ACTIVERANGE) &&
- mouseY<(this._rect.y + this._rect.height -Constant.ACTIVERANGE)) {
- return true ;
- }
- return false ;
- }
- }
- }
代码三:
- package com.wdxc {
- import flash.display.MovieClip;
- import flash.display.Sprite
- import flash.display.* ;
- import flash.events.MouseEvent ;
- import flash.geom.Matrix ;
-
-
- public class ImageRotation extends Sprite{
-
-
- private var _bitmap:Bitmap ;
-
- private var _x:Number ;
- private var _y:Number ;
- private var _w:Number ;
- private var _h:Number ;
-
-
- public function ImageRotation() {
-
- _bitmap = Main.SCENE.bitmap ;
- _x = _bitmap.x ;
- _y = _bitmap.y ;
- _w = _bitmap.width ;
- _h = _bitmap.height ;
- cancle_btn.addEventListener(MouseEvent.CLICK, cancleHandler);
-
- left_btn.addEventListener(MouseEvent.CLICK, leftRotationHandler);
- right_btn.addEventListener(MouseEvent.CLICK, rightRotationHandler) ;
- save_btn.addEventListener(MouseEvent.CLICK, applicationHandler);
-
-
- Main._handerState = 10 ;
-
- }
-
-
-
-
- private function cancleHandler(e:MouseEvent):void {
-
- Main._handerState = 0 ;
- this.remove();
- }
-
- public function remove():void {
- Main.SCENE.bitmap.x = _x ;
- Main.SCENE.bitmap.y = _y ;
- Main.SCENE.bitmap.rotation = 0 ;
- left_btn.removeEventListener(MouseEvent.CLICK, leftRotationHandler);
- cancle_btn.removeEventListener(MouseEvent.CLICK, cancleHandler) ;
- save_btn.removeEventListener(MouseEvent.CLICK, applicationHandler);
-
-
- this.stage.removeChild(this) ;
- }
-
- private function applicationHandler(e:MouseEvent):void {
-
- Main.SCENE.addVagueBg();
- Main.SCENE.addLoadingBar();
-
- var server :ImageService = new ImageService();
- server.photoid = Main.SCENE.photoid ;
- server.submitRotation(fixAng( _bitmap.rotation) );
-
- left_btn.removeEventListener(MouseEvent.CLICK, leftRotationHandler);
- cancle_btn.removeEventListener(MouseEvent.CLICK, cancleHandler) ;
- save_btn.addEventListener(MouseEvent.CLICK, applicationHandler);
- this.stage.removeChild(this) ;
-
- Main._handerState = 2 ;
-
- }
-
-
-
- private function rightRotationHandler(e:MouseEvent):void {
- var _angle = fixAng(_bitmap.rotation) ;
-
- if (_angle== 0) {
- _bitmap.x = _x + (_h + _w) / 2 ;
- _bitmap.y = _y+(_h - _w) / 2 ;
-
- }
- else if (_angle == 90) {
-
- _bitmap.x = _x + _w ;
- _bitmap.y = _y + _h ;
- }
- else if (_angle== 180) {
- _bitmap.x = _x - (_h - _w) / 2;
- _bitmap.y = _y + (_w+_h)/2 ;
-
- }
- else if (_angle == 270) {
- _bitmap.x = _x ;
- _bitmap.y = _y;
-
- }
-
- _bitmap.rotation += 90 ;
- _angle = fixAng( _bitmap.rotation) ;
- trace("angle="+_angle);
- }
- private function leftRotationHandler(e:MouseEvent):void {
-
- var _angle = fixAng( _bitmap.rotation) ;
- if (_angle == 0) {
- _bitmap.x = _x - (_h - _w) / 2;
- _bitmap.y = _y + (_w+_h)/2 ;
- }
- else if (_angle == 270) {
- _bitmap.x = _x + _w ;
- _bitmap.y = _y + _h ;
- }
- else if (_angle == 180 ){
- _bitmap.x = _x + (_h + _w) / 2 ;
- _bitmap.y = _y+(_h - _w) / 2 ;
-
- }
- else if (_angle == 90) {
- _bitmap.x = _x ;
- _bitmap.y = _y;
- }
-
- _bitmap.rotation -= 90 ;
- trace("angle="+_angle);
- }
-
-
- public static function fixAng (_ang:Number){
- var _ang:Number = _ang % 360;
- var ang:Number = _ang % 360 < 0 ? _ang + 360 : _ang;
- return ang;
- }
-
- }
-
- }
代码四:
代码五:
Top