(转AS3)利用BitmapData.draw对位图进行翻转缩放操作
来源:互联网 发布:中世纪2优化9经验 编辑:程序博客网 时间:2024/05/22 10:45
Sprite对象有2个关于缩放的属性scaleX、scaleY,分别是缩放x轴和y轴。
看下面代码:
var c:Sprite = new Sprite;
c.x = 200;
addChild(c);
var s:Sprite = new Sprite;
s.graphics.beginFill(0xff0000);
s.graphics.drawRect(0,0,100,100);
s.graphics.endFill();
s.graphics.beginFill(0x00ff00);
s.graphics.drawRect(100,0,100,100);
s.graphics.endFill();
c.addChild(s);
//s.scaleX = -1;
c.x = 200;
addChild(c);
var s:Sprite = new Sprite;
s.graphics.beginFill(0xff0000);
s.graphics.drawRect(0,0,100,100);
s.graphics.endFill();
s.graphics.beginFill(0x00ff00);
s.graphics.drawRect(100,0,100,100);
s.graphics.endFill();
c.addChild(s);
//s.scaleX = -1;
下图分别是注释和没注释最后一句代码的运行结果:
把注释去掉可以发现,该对象已经水平翻转了一下,不过看过来却好像坐标往左移了200个像素,实际上只是像素变了,坐标并没有变。
不过这里可以发现,当把scaleX会水平翻转,那scaleY会怎么样呢?没错,是垂直翻转了!
由此为基础,使用BitmapData.draw,配合Matrix,就可以实现一个位图或者对象的水平翻转和垂直翻转,下面是实现代码:
package org.easily.utils
{
import flash.display.BitmapData;
import flash.geom.Matrix;
public class BitmapDataUtils
{
//水平翻转一个位图
public static function flipHorizontal(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.a = -1;
matrix.tx = bmpData.width;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//垂直翻转一个位图
public static function flipVertical(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.d = -1;
matrix.ty = bmpData.height;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//缩放位图
public static function scaleBitmapData(bmpData:BitmapData, scaleX:Number, scaleY:Number):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.scale(scaleX, scaleY);
var bmpData_:BitmapData = new BitmapData(scaleX * bmpData.width, scaleY * bmpData.height, true, 0);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
}
}
{
import flash.display.BitmapData;
import flash.geom.Matrix;
public class BitmapDataUtils
{
//水平翻转一个位图
public static function flipHorizontal(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.a = -1;
matrix.tx = bmpData.width;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//垂直翻转一个位图
public static function flipVertical(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.d = -1;
matrix.ty = bmpData.height;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//缩放位图
public static function scaleBitmapData(bmpData:BitmapData, scaleX:Number, scaleY:Number):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.scale(scaleX, scaleY);
var bmpData_:BitmapData = new BitmapData(scaleX * bmpData.width, scaleY * bmpData.height, true, 0);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
}
}
最后一个缩放位图的方法适用于等比例缩放一个对象,位图引擎里面应该也有类似的实现。
0 0
- (转AS3)利用BitmapData.draw对位图进行翻转缩放操作
- AS3对外部加载的位图进行九宫格缩放
- (转AS3)BitmapData.draw比BitmapData.copyPixel能做得更多
- (AS3)BitmapData.draw比BitmapData.copyPixel能做得更多
- As3.0中的位图(Bitmap/BitmapData)编程
- As3.0中的位图(Bitmap/BitmapData)编程
- As3.0中的位图(Bitmap/BitmapData)编程
- As3.0中的位图(Bitmap/BitmapData)编程
- open外面位图 对位图进行缩放的方法
- BitmapData.draw
- bitmapdata,draw
- [AS3] 解决BitmapData.draw()安全沙箱问题!
- as3中bitmapData中draw方法重新理解
- as3 影片剪辑(MovieClip)转换为位图(BitmapData)
- Pygame学习(3)-----如何对图像进行翻转,缩放,旋转
- iOS 利用UIScrollView 对图片进行缩放
- 对as3数组进行group分组操作
- 利用Jimi进行图片缩放操作
- java反射的应用
- V4L2框架分析学习
- mysql 事务
- Hibernate4.3.8 buildSessionFactory过时解决方案HibernateUtil
- 关于HBASE过滤器的一些基本实例
- (转AS3)利用BitmapData.draw对位图进行翻转缩放操作
- Makefile 中:= ?= += =的区别
- 部署中排除特定文件或文件夹
- web开发新手学习心得和目标计划
- HTML5 实现Link跳线效果
- 国电南宁借助紫光档案统一归档数据管理平台
- 第四章 使用OpenCV探测来至运动的结构——Chapter 4:Exploring Structure from Motion Using OpenCV
- windows2008环境变量
- 关于图结构的相似度比较