flash 交互操作 裁剪位图

本文介绍了在Flash中实现截图功能,通过位图的复制像素技术。详细讲解了如何绘制矩形、获取位图以及实现交互效果。文章提供了一个实现此功能的Demo,包括基类`Item`、接口`ISelector`和`Selector`类的实现,涉及绘图API和鼠标交互,特别强调了Rectangle类在截图功能中的应用。
摘要由CSDN通过智能技术生成
               

  玩过截图的人都知道截图是怎样一回事,通过截取图片一个地方就能够获取到图片某一个片段。这一个部分在flash 里面可以利用位图的复制像素来实现。通过copyPixels 或者draw 能够获取像素。

 

  现在我们讨论一个话题:在flash里面怎样实现这种截图? 带着这个问题,尝试制作一个demo出来。功能就是获取位图。

 

  所需要的材料:第一就是flash绘图API ,第二就是位图像素操作。利用这两个我们就能够实现出这种交互效果。

 设计的图案:

图案

 

 

 

制作思路:首先知道怎样绘制一个矩形,可以上网搜索一下,或者查询一些flash绘图API 是如何操作的。借助绘制这股矩形,我们就能截取到我们所需要的片段。

 关系图

接下来,为程序写一个基类:Item.as

定义一些常用的方法和属性。

例如绘制矩形。获取位图,定义线条的样式等,判断矩形是否有效

这些方法都是定义在这个基础类当中。

 

 

 

 

package org.summerTree{ //选择类基本设置 import flash.display.Sprite; import flash.geom.Rectangle; import flash.events.EventDispatcher; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Point; public class Item extends EventDispatcher {  public var LineColor:int=0x0000ff;//线条颜色  public var FillColor:int=0x0000ff;//填充的颜色  public var FillAlpha:Number=0.1;  public function Item()  {  }  //绘制矩形的基本方法  protected function DrawRect(shape:Sprite,rect:Rectangle):void  {   shape.graphics.clear();   shape.graphics.lineStyle(1,LineColor,1);   shape.graphics.beginFill(FillColor,FillAlpha);   shape.graphics.drawRect(rect.x,rect.y,rect.width,rect.height);   shape.graphics.endFill();  }  //判断rect是否有效  public function checkRect(rect:Rectangle):Boolean  {   return rect != null?true:false;  }    //定义样式  public function setStyle(lcolor:int,fcolor:int,aplha:Number):void  {   this.LineColor=lcolor;   this.FillColor=fcolor;   this.FillAlpha=aplha;  }  //获取位图  public function getImage(source:Bitmap,rect:Rectangle):Bitmap  {   var bitmapdata:BitmapData = source.bitmapData;   var Width:Number=Math.abs(rect.width);   var Height:Number=Math.abs(rect.height);   var temp:Rectangle;   var newImage:BitmapData;   if (rect.width>0 && rect.height>0)   {    newImage=new BitmapData(Width,Height, false);//    newImage.copyPixels(bitmapdata,rect,new Point(0,0));   } else if (rect.width<0 && rect.height>0)   {    newImage=new BitmapData(Width,Height, false);//     temp=new Rectangle(rect.x-Width,rect.y,Width,Height);    newImage.copyPixels(bitmapdata,temp,new Point(0,0));   } else if (rect.width<0 && rect.height<0)   {    newImage=new BitmapData(Widt

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值