<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import mx.core.UIComponent; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BitmapDataChannel; private var bm:Bitmap; private var bmd:BitmapData; private function image_complete(evt:Event):void { /* Create Bitmap from Image content. */ bm = img.content as Bitmap;
/* Create new BitmapData object. */ bmd = new BitmapData(img.contentWidth, img.contentHeight);
/* Draw Bitmap into BitmapData. */ bmd.draw(bm.bitmapData); process(imgr,getRedChannelData(bmd)); process(imgg,getGreenChannelData(bmd)); process(imgb,getBlueChannelData(bmd)); process(gimgr,getRedChannelGrayScaleData(bmd)); process(gimgg,getGreenChannelGrayScaleData(bmd)); process(gimgb,getBlueChannelGrayScaleData(bmd)); process(gimg,getGrayscaleData(bmd)); } //用位图数据填充Image控件 private function process(image:Image,bitmapData:BitmapData):void { image.graphics.beginBitmapFill(bitmapData); image.graphics.drawRect(0,0,bitmapData.width,bitmapData.height); image.graphics.endFill(); } private function image_mouseMove(evt:MouseEvent):void { /* Get the pixel currently under the mouse cursor. */ //var color:int = bmd.getPixel(evt.localX, evt.localY);
/* Convert the color value from a number to Hex string. */ //var colorStr:String = color.toString(16).toUpperCase();
/* Set the swatch Box instance's backgroundColor style to the color under the mouse cursor. */ //swatch.setStyle("backgroundColor", color);
/* Make sure colorStr is at least 6 characters. */ //colorStr = "000000" + colorStr;
/* Make sure colorStr is at MOST 6 characters. */ //lbl.text = "#" + colorStr.substr(colorStr.length - 6); } //获取红色通道中每个像素的值 private function getRedChannelData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { data.setPixel(i,j,getRed(source.getPixel(i,j)) << 16); } } return data; } //获取红色通道灰度模式下每个像素的值 private function getRedChannelGrayScaleData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { var red:uint = getRed(source.getPixel(i,j)); data.setPixel(i,j,mergeRGB(red,red,red)); } } return data; } private function getGreenChannelData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { data.setPixel(i,j,getGreen(source.getPixel(i,j)) << 8); } } return data; } private function getGreenChannelGrayScaleData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { var green:uint = getGreen(source.getPixel(i,j)); data.setPixel(i,j,mergeRGB(green,green,green)); } } return data; } private function getBlueChannelData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { data.setPixel(i,j,getBlue(source.getPixel(i,j))); } } return data; } private function getBlueChannelGrayScaleData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { var blue:uint = getBlue(source.getPixel(i,j)); data.setPixel(i,j,mergeRGB(blue,blue,blue)); } } return data; } //获取灰度模式下每个像素的值 private function getGrayscaleData(source:BitmapData):BitmapData { var data:BitmapData = new BitmapData(source.width,source.height); for(var i:Number = 1;i<source.width;i++) { for(var j:Number =1 ;j<source.height;j++) { var pixel:uint = source.getPixel(i,j); var r:uint = getRed(pixel); var g:uint = getGreen(pixel); var b:uint = getBlue(pixel); var gray:uint = rgb2gray(r,g,b); data.setPixel(i,j,mergeRGB(gray,gray,gray)); } } return data; } //获取红色通道中该像素的值 private function getRed(rgb:uint):uint { if(!isHex24(rgb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0xff0000; var red:uint = (rgb & mask) >> 16; return red; } //当该像素色彩值包含alpha通道的值时,获取红色通道中该像素的值 private function getRed32(argb:uint):uint { if(!isHex32(argb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0x00ff0000; var red:uint = (argb & mask) >> 16; return red; } private function getGreen(rgb:uint):uint { if(!isHex24(rgb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0x00ff00; var green:uint = (rgb & mask) >> 8; return green; } private function getGreen32(argb:uint):uint { if(!isHex32(argb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0x0000ff00; var green:uint = (argb & mask) >> 8; return green; } private function getBlue(rgb:uint):uint { if(!isHex24(rgb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0x0000ff; var blue:uint = (rgb & mask); return blue; } private function getBlue32(argb:uint):uint { if(!isHex32(argb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0x000000ff; var blue:uint = (argb & mask); return blue; } //获取该像素的alpha值 private function getAlpha(argb:uint):uint { if(!isHex32(argb)) { throw new Error("rgb value is not correct!"); } var mask:uint = 0xff000000; var alpha:uint = (argb & mask) >>> 24; return alpha; } private function mergeRGB(red:uint,green:uint,blue:uint):uint { return (red<<16)|(green<<8)|blue; } private function mergeARGB(alpha:uint,red:uint,green:uint,blue:uint):uint { return (alpha << 24)|(red<<16)|(green<<8)|blue; } //判断是否为32位16进制数 private function isHex32(hex:uint):Boolean { return hex.toString(16).length == 8; } //判断是否为24位16进制数 private function isHex24(hex:uint):Boolean { return hex.toString(16).length == 6; } //网上摘录的算法,用于将RGB图像转换为灰度图像,按像素转换。 private function rgb2gray(R:Number,G:Number,B:Number):Number { var x:Number; var y:Number; var z:Number; var gray:Number; var r:Number = R/255.0; var g:Number = G/255.0; var b:Number = B/255.0; r = Math.pow((r+0.055)/1.055,2.4); g = Math.pow((g+0.055)/1.055,2.4); b = Math.pow((b+0.055)/1.055,2.4); y = r*0.222+g*0.717+b*0.061; x = y*0.964; z = y * 0.825; gray = 3.134 * x -1.617*y -0.490*z; gray = Math.pow(gray,1/2.4)*1.055-0.055; gray = gray*255; //gray = (1-(gray/255))*100; return gray; //return R*0.3+G*0.59+B*0.11; } ]]> </mx:Script> <mx:Zoom id="zoom" /> <mx:VBox id="container" height="100%" width="100%"> <mx:Label text="origin"/> <mx:Image id="img" source="images/test.gif" completeEffect="{zoom}" complete="image_complete(event);" mouseMove="image_mouseMove(event)"/> <mx:Label text="channel"/> <mx:HBox> <mx:VBox> <mx:Label text="red"/> <mx:Image id="imgr" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> <mx:VBox> <mx:Label text="green"/> <mx:Image id="imgg" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> <mx:VBox> <mx:Label text="blue"/> <mx:Image id="imgb" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> </mx:HBox> <mx:Label text="grayscale channel"/> <mx:HBox> <mx:VBox> <mx:Label text="red"/> <mx:Image id="gimgr" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> <mx:VBox> <mx:Label text="green"/> <mx:Image id="gimgg" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> <mx:VBox> <mx:Label text="blue"/> <mx:Image id="gimgb" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> </mx:VBox> </mx:HBox> <mx:Label text="grayscale mode"/> <mx:Image id="gimg" width="{img.width}" height="{img.height}" mouseMove="image_mouseMove(event)"/> <mx:HBox> <mx:Box id="swatch" width="{lbl.height}" height="{lbl.height}"/> <mx:Label id="lbl" width="100"/> </mx:HBox> </mx:VBox> </mx:Application>
|
相关推荐
第1篇 ActionScript3.0语言基础 第1章 ActionScript3.0概述 第2章 搭建ActionScript3.0开发环境 第3章 ActionScript3.0语法 第2篇 ActionScript3.0面向对象特性 第4章 ActionScript3.0面向对象编程 第...
拉登大叔最近出的那本书的源码,共享给大家,有问题私信,评论没办法回复
第 1 章 绘图API 1.1 绘图API历史回顾 1.2 早期的绘图功能 基本命令回顾 绘制简单的图形 绘制渐变填充线条 位图填充图形 1.3 现在的绘图功能 复制图形数据 绘制位图笔触 存储路径数据 ...渲染三角形
actionscript3.0开发的进度显示条项目
《ActionScript 3.0 语言和组件参考》概述 《ActionScript 3.0 语言参考》是 Flash® Player 和 Adobe AIR™ 应用程序编程接口 (API) 的参考手册。 此版本包括支持 Adobe AIR 运行时环境的新 ActionScript 类、...
最专业的最专业的最专业的ActionScript 3.0 ActionScript 3.0 ActionScript 3.0 ActionScript 3.0 ActionScript 3.0
本书全面介绍了ActionScript 3.0的基本语法、类的架构以及面向对象程序的设计理念。内容安排上既适合刚刚接触到ActionScript脚本语言的初学者,也照顾到学习过ActionScript之前版本有一定编程经验的读者。 鉴于...
本书详细地介绍了 actionscript 3.0的基础知识,包括 actionscript 3.0语言、actionscript 3.0对象的操作方法、显示列表的使用、事件模型、加载外部素材、可视化编程以及利用声音和视频增强应用程序等方面的知识,并...
ActionScript 3.0 提供了可靠的编程模型,具备面向对象编程的基本知识的开发人员对此模 型会感到似曾相识。ActionScript 3.0 中的一些主要功能包括: ■ 一个新增的 ActionScript 虚拟机,称为 AVM2,它使用全新的...
ActionScript3.0 中文版 ActionScript3.0 api 中文版说明文档
ActionScript 3.0 语言和组件参考概述Adobe Flex 2 语言参考ActionScript 3.0 语言和组件参考是适用于 Flash® Player 应用程序编程接口 (API) 的参考手册。 Adobe Flex 2 语言参考ActionScript 3.0 语言和组件...
ActionScript3.0完全自学手册电子教案
Foundation ActionScript 3.0 Animation Making Things Move ActionScript 3.0
用ActionScript 3.0动态绘制正弦曲线,附带源文件(包括一个.fla文件、一个.as文件、一个.swf文件)
第5篇 ActionScript3.0图形编程 第15章 ActionScript3.0中的几何对象 第16章 ActionScript3.0图形绘制 第17章 ActionScript3.0运动编程 第18章 位图处理 第19章 ActionScript3.0滤镜 第6篇 ...
《ActionScript 3.0 语言和组件参考》概述《ActionScript 3.0 语言参考》是 Flash® Player 和 Adobe AIR™ 应用程序编程接口 (API) 的参考手册。 此版本包括支持 Adobe AIR 运行时环境的新 ActionScript 类、方法...
ActionScript3.0cookbook中文版 ActionScript3.0cookbook中文版 ActionScript3.0cookbook中文版
《ActionScript 3.0 语言和组件参考》中文版概述 下面的《ActionScript 3.0 语言和组件参考》是 Flash® Player 应用程序编程接口 (API) 的参考手册。 下面的《ActionScript 3.0 语言和组件参考》提供 ActionScript...
actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨