package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.utils.ByteArray; /**
* ...
* @author Frost.Yen
*/
public class CutOut extends Sprite
{
private var ldr:Loader;
private var cutContainer:Sprite;//存放裁剪的图片的容器
private var primitiveContainer:Sprite;//存放原始图片的容器
private var frame:Shape;//裁剪框
private var downPoint:Point=new Point();
private var bytearr:ByteArray=new ByteArray(); public function CutOut():void
{
init();
} private function init():void
{
this.graphics.beginFill(0xcccccc);
this.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
this.graphics.endFill(); cutContainer = new Sprite();
primitiveContainer = new Sprite();
frame = new Shape(); cutContainer.x = 400; this.addChild(primitiveContainer);
this.addChild(cutContainer);
this.addChild(frame); ldr = new Loader();
ldr.load(new URLRequest("http://hiphotos.baidu.com/frostyen/pic/item/7e49d8b53f6b48ffd9335aa2.jpg"));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
primitiveContainer.addChild(ldr);
this.addEventListener(MouseEvent.MOUSE_DOWN, onStageDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onStageUp);
}
private function onStageDown(e:MouseEvent):void
{
while (cutContainer.numChildren>0)
{
cutContainer.removeChildAt(0);
} downPoint.x = mouseX;
downPoint.y = mouseY;
frame.graphics.clear();
primitiveContainer.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
} private function onMove(e:MouseEvent):void
{
frame.graphics.clear();
frame.graphics.lineStyle(1,0xff00ff);
frame.graphics.drawRect(0, 0, mouseX - downPoint.x, mouseY - downPoint.y);
frame.x = downPoint.x;
frame.y = downPoint.y;
} private function onStageUp(e:MouseEvent):void
{
primitiveContainer.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
if (frame.width != 0)
{
var bmpd1:BitmapData = new BitmapData(primitiveContainer.width,primitiveContainer.height);
bmpd1.draw(primitiveContainer);
bytearr = bmpd1.getPixels(new Rectangle(frame.x,frame.y,frame.width,frame.height));
bytearr.position = 0;
var bmpd2:BitmapData = new BitmapData(frame.width,frame.height);
try
{
bmpd2.setPixels(new Rectangle(0,0,frame.width,frame.height),bytearr);
}
catch (err:Error)
{
trace(err.message);//若裁剪框拉的范围超出原始图像范围会报此错,若解决,需深究.
frame.graphics.clear();
return;
}
var bmp:Bitmap = new Bitmap(bmpd2);
cutContainer.addChild(bmp);
} } private function onComplete(e:Event):void
{
ldr.scaleX = ldr.scaleY = 0.6;
} } }

[ActionScript 3.0] 框选裁剪的更多相关文章

  1. [转]结合轮廓显示,实现完整的框选目标(附Demo代码)

    原地址:http://www.cnblogs.com/88999660/articles/2887078.html 几次看见有人问框选物体的做法,之前斑竹也介绍过,用画的框生成的视椎,用经典图形学的视 ...

  2. unity3d结合轮廓显示,实现完整的框选目标(附Demo代码)

    原地址:http://dong2008hong.blog.163.com/blog/static/469688272013111554511948/ 在unity里实现,其实很简单,因为有两个前提:1 ...

  3. jquery 拖拽,框选的一点积累

    拖拽draggable,框选 selectable,按ctrl多选,临近辅助对齐,从工具栏拖工具  等,和jqueryui的selectable不同,是在一个父div里框选子div(类似框选文件),一 ...

  4. ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0,现把学习结果分享一下,希望对新手有帮助. 目录 ActionScript 3.0简介 Hello ...

  5. [转]ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    本文转自:http://www.cnblogs.com/artwl/p/3396330.html 近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0, ...

  6. JavaScript实现框选效果

    <html> <head> <title>region</title> <style> body { margin: 0; padding: ...

  7. js实现鼠标拖动框选元素小狗

    方法一: <html> <head></head> <style> body{padding:100px;} .fileDiv{float:left;w ...

  8. unity实现框选效果

    思路: 在uinity中既可以将屏幕坐标转换为世界坐标,也可以将世界坐标转换为屏幕坐标.这样的话我们就可以通过判断物体在世界坐标转换为平幕坐标是否在鼠标框选的矩形区域坐标内,来判断物体是否在框选范围. ...

  9. python PIL图像处理-框选

    框选图中位置 代码 from PIL import Image,ImageDraw,ImageFont,ImageFilter import random #--------------------- ...

随机推荐

  1. 二维码生成插件qrious及网站扫码登录的一些理解

    什么是二维码 ​ 二维码又称QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型. ...

  2. react.js 各种小测试笔记

    首先看一个 基础html  至于其中的 js 问价大家去官网下载就好了. <html> <head> <script src="../build/react.j ...

  3. Window: move\copy\xcopy

    Move 移动文件和重命名文件与目录. 要移动一个或多个文件: MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination 要重命名目录: MO ...

  4. easyui图标大全

    .icon-blank{ background:url('icons/blank.gif') no-repeat; } .icon-add{ background:url('icons/edit_ad ...

  5. real-Time Correlative Scan Matching

    启发式算法(heuristic algorithm)是相对于最优化算法提出的.一个问题的最优算法求得该问题每个实例的最优解.启发式算法可以这样定义:一个基于直观或经验构造的算法,在可接受的花费(指计算 ...

  6. tomcat端口作用

    <Server port="8005" shutdown="SHUTDOWN">   <Connector port="8080&q ...

  7. Perl 学习笔记-输入输出

    1.读取标准输入<STDIN>(行输入操作=> 读取一行直到换行符) chomp($line = <STDIN>); # 读取一行并去掉最后的换行符(不会自动去掉) pr ...

  8. WireShark抓包的pcap文件格式分析

    http://www.360doc.com/content/14/0220/11/15257968_354157537.shtml http://www.360doc.com/content/14/0 ...

  9. osgQt支持触摸屏

    1. osgQt的构造函数添加:setAttribute(Qt::WA_AcceptTouchEvents);//wyh 2. event()修改,支持触摸时间 bool GLWidget::even ...

  10. SurfaceView实时绘图,视频流