﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-xiaoguozi's Blog-随笔分类-Flex</title><link>http://www.cppblog.com/guojingjia2006/category/11421.html</link><description>Happy coding</description><language>zh-cn</language><lastBuildDate>Fri, 10 Jun 2011 14:34:19 GMT</lastBuildDate><pubDate>Fri, 10 Jun 2011 14:34:19 GMT</pubDate><ttl>60</ttl><item><title>BitmapData 详解（一）(转）</title><link>http://www.cppblog.com/guojingjia2006/archive/2011/06/10/148443.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Fri, 10 Jun 2011 09:39:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2011/06/10/148443.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/148443.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2011/06/10/148443.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/148443.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/148443.html</trackback:ping><description><![CDATA[<div align="left">在<span>ActionScript 3.0中，可以创建位图图像，还可以把外部的位图图像加载到Flash Player中。使用位图类，可以处理位图的像素和杂点。通过滤镜类，还可以增加位图的各种滤镜效果。</span></div>
<div align="left"><strong>19.1&nbsp; </strong><strong>位图类</strong></div>
<div align="left">常用的有关位图的类有三个：<span>Bitmap类、BitmapData类和BitmapDataChannel类。Bitmap类用来显示位图图像，BitmapData类用来处理位图，BitmapDataChannel类是个枚举值，表示使用的通道。</span></div>
<div align="left"><strong>&nbsp;19.1.1&nbsp; Bitmap</strong><strong>类</strong></div>
<div align="left">Bitmap类表示位图图像的显示对象。可以使用<span>Bitmap类的构造函数创建图像，也可以使用Loader类加载外部图像。Bitmap类常用的属性如表19.1所示。</span></div>
<div align="left">表19.1&nbsp; Bitmap类常用的属性</div>
<div align="center">
<table cellspacing="0" cellpadding="0" width="559" border="0">
<tbody>
<tr>
<td valign="top" width="101">
<div align="center"><sup>属</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>性</sup></div></td>
<td valign="top" width="458">
<div align="center"><sup>说</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>明</sup></div></td></tr>
<tr>
<td valign="top" width="101">
<div align="left"><sup>bitmapData</sup></div></td>
<td valign="top" width="458">
<div align="left"><sup>被引用的</sup><sup>BitmapData</sup><sup>对象</sup></div></td></tr>
<tr>
<td valign="top" width="101">
<div align="left"><sup>pixelSnapping</sup></div></td>
<td valign="top" width="458">
<div align="left"><sup>控制</sup><sup>Bitmap</sup><sup>对象是否贴紧至最近的像素</sup></div></td></tr>
<tr>
<td valign="top" width="101">
<div align="left"><sup>smoothing</sup></div></td>
<td valign="top" width="458">
<div align="left"><sup>控制在缩放时是否对位图进行平滑处理</sup></div></td></tr></tbody></table></div>
<div align="left"><strong>&nbsp;19.1.2&nbsp; BitmapData</strong><strong>类</strong></div>
<div align="left">BitmapData类用来处理<span>Bitmap对象的数据。BitmapData类可以在程序运行时，任意调整位图的大小、透明度、像素等。BitmapData类常用的属性如表19.2所示，常用的方法如表19.3所示。</span></div>
<div align="left">表19.2&nbsp; BitmapData类常用的属性</div>
<div align="center">
<table cellspacing="0" cellpadding="0" width="559" border="0">
<tbody>
<tr>
<td valign="top" width="177">
<div align="center"><sup>属</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>性</sup></div></td>
<td valign="top" width="366">
<div align="center"><sup>说</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>明</sup></div></td></tr>
<tr>
<td valign="top" width="177">
<div align="left"><sup>height</sup></div></td>
<td valign="top" width="366">
<div align="left"><sup>位图图像的高度</sup></div></td></tr>
<tr>
<td valign="top" width="177">
<div align="left"><sup>rect</sup></div></td>
<td valign="top" width="366">
<div align="left"><sup>定义位图图像大小和位置的矩形</sup></div></td></tr>
<tr>
<td valign="top" width="177">
<div align="left"><sup>transparent</sup></div></td>
<td valign="top" width="366">
<div align="left"><sup>定义位图图像是否支持每个像素具有不同的透明度</sup></div></td></tr>
<tr>
<td valign="top" width="177">
<div align="left"><sup>width</sup></div></td>
<td valign="top" width="366">
<div align="left"><sup>位图图像的宽度</sup></div></td></tr></tbody></table></div>
<div align="left">表19.3&nbsp; BitmapData对象常用的方法</div>
<div align="center">
<table cellspacing="0" cellpadding="0" width="559" border="0">
<tbody>
<tr>
<td valign="top" width="123">
<div align="center"><sup>方</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>法</sup></div></td>
<td valign="top" width="437">
<div align="center"><sup>说</sup><sup>&nbsp;&nbsp;&nbsp; </sup><sup>明</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>applyFilter</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>取得一个源图像和一个滤镜对象，并生成过滤的图像</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>clone</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>返回一个新的</sup><sup>BitmapData</sup><sup>对象，它是对原始实例的克隆，包含与原始实例所含位图完全相同的副本</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>colorTransform</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>使用</sup><sup>ColorTransform</sup><sup>对象调整位图图像的指定区域中的颜色值</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>compare</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>比较两个</sup><sup>BitmapData</sup><sup>对象</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>copyChannel</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>将数据从另一个</sup><sup>BitmapData</sup><sup>对象或当前</sup><sup>BitmapData</sup><sup>对象的一个通道传输到当前</sup><sup>BitmapData</sup><sup>对象的某个通道中</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>copyPixels</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>为没有拉伸、旋转或色彩效果的图像之间的像素处理提供一个快速例程</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>dispose</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>释放用来存储</sup><sup>BitmapData</sup><sup>对象的内存</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>draw</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>使用</sup><sup>Flash Player</sup><sup>矢量渲染器在位图图像上绘制</sup><sup>source</sup><sup>显示对象</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>fillRect</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>使用指定的</sup><sup>ARGB</sup><sup>颜色填充一个矩形像素区域</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>floodFill</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>对图像执行倾倒填充操作，从（</sup><sup>x, y</sup><sup>）坐标开始，填充一种特定的颜色</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>generateFilterRect</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>已知</sup><sup>BitmapData</sup><sup>对象、源矩形和滤镜对象，确定</sup><sup>applyFilter()</sup><sup>方法调用所影响的目标矩形</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>getColorBoundsRect</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>确定矩形区域是将位图图像中指定颜色的所有像素完全包括起来（如果将</sup><sup>findColor</sup><sup>参数设置为</sup><sup>true</sup><sup>），还是将不包括指定颜色的所有像素完全包括起来（如果将</sup><sup>findColor</sup><sup>参数设置为</sup><sup>false</sup><sup>）</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>getPixel</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>返回一个整数，它表示</sup><sup>BitmapData</sup><sup>对象中在特定点（</sup><sup>x, y</sup><sup>）</sup><sup>&nbsp;</sup><sup>处的</sup><sup>RGB </sup><sup>像素值</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>getPixel32</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>返回一个</sup><sup>ARGB</sup><sup>颜色值，它包含</sup><sup>Alpha</sup><sup>通道数据和</sup><sup>RGB</sup><sup>数据</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>getPixels</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>从像素数据的矩形区域生成一个字节数组</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>hitTest</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>在一个位图图像与一个点、矩形或其他位图图像之间执行像素级的点击检测</sup><sup>&nbsp;</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>lock</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>锁定图像，以使引用</sup><sup>BitmapData</sup><sup>对象的任何对象（如</sup><sup>Bitmap</sup><sup>对象）在此</sup><sup>BitmapData</sup><sup>对象更改时不会更新</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>merge</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>对每个通道执行从源图像向目标图像的混合</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>noise</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>使用表示随机杂点的像素填充图像</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>paletteMap</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>重新映射一个具有最多四组调色板数据（每个通道一组）的图像中的颜色通道值</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>perlinNoise</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>生成</sup><sup>Perlin</sup><sup>杂点图像</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>pixelDissolve</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>执行源图像到目标图像的像素溶解，或使用同一图像执行像素溶解</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>scroll</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>按某一（</sup><sup>x, y</sup><sup>）像素量滚动图像</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>setPixel</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>设置</sup><sup>BitmapData</sup><sup>对象的单个像素</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>setPixel32</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>设置</sup><sup>BitmapData</sup><sup>对象单个像素的颜色和</sup><sup>Alpha</sup><sup>透明度值</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>setPixels</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>将字节数组转换为像素数据的矩形区域</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>threshold</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>根据指定的阈值测试图像中的像素值，并将通过测试的像素设置为新的颜色值</sup></div></td></tr>
<tr>
<td valign="top" width="123">
<div align="left"><sup>unlock</sup></div></td>
<td valign="top" width="437">
<div align="left"><sup>解除锁定图像，以使引用</sup><sup>BitmapData</sup><sup>对象的任何对象（如</sup><sup>Bitmap</sup><sup>对象）在此</sup><sup>BitmapData</sup><sup>对象更改时更新</sup></div></td></tr></tbody></table></div>
<div align="left"><strong>&nbsp;19.1.3&nbsp; </strong><strong>创建位图类</strong></div>
<div align="left">通常情况下，<span>Bitmap类和BitmapData类是结合在一起使用的。Bitmap类的构造函数的语法格式如下所示：</span></div>
<div align="left">Bitmap(bitmapData:BitmapData = null, pixelSnapping:String = "auto", smoothing:Boolean = false)</div>
<div align="left">其各个参数的说明如下。</div>
<div align="left">&#8212;&nbsp; bitmapData：被引用的<span>BitmapData对象。</span></div>
<div align="left">&#8212;&nbsp; pixelSnapping：默认值为<span>auto，表示Bitmap对象是否贴紧至最近的像素。</span></div>
<div align="left">&#8212;&nbsp; smoothing：默认值为<span>false，表示在缩放时是否对位图进行平滑处理。</span></div>
<div align="left">BitmapData类的构造函数的语法格式如下所示：</div>
<div align="left">BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)</div>
<div align="left">其各个参数的说明如下。</div>
<div align="left">&#8212;&nbsp; width：位图图像的宽度，以像素为单位。</div>
<div align="left">&#8212;&nbsp; height：位图图像的高度，以像素为单位。</div>
<div align="left">&#8212;&nbsp; transparent：指定位图图像是否支持每个像素具有不同的透明度。</div>
<div align="left">&#8212;&nbsp; fillColor：用于填充位图图像区域的<span>32位ARGB颜色值。</span></div>
<div align="left">下面的示例使用两个位图类，创建一个矩形，代码如下所示：</div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample(</div>
<div align="left">)</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, true, 0x500066FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建Bitmap类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var image:Bitmap = new Bitmap(bitmap);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置显示位置</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.x = 90;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.y = 50;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 增加到舞台</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(image);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，结果如图<span>19.1所示。</span></div>
<div align="left">图19.1&nbsp; 创建位图类</div>
<div align="left"><strong>&nbsp;19.1.4&nbsp; </strong><strong>加载外部图像</strong></div>
<div align="left">除了在内部创建位图之外，还可以加载外部的图像到位图中。加载外部的图像，需要用到<span>Loader对象。通过Loader对象的load()方法，可以加载外部的URL。下面的示例使用Loader对象，加载外部图像到位图中，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Loader;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.events.Event;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.net.URLRequest;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private var loader:Loader = new Loader();</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 侦听数据加载</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 外部图像URL</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; loader.load(new URLRequest("Bitmap.jpg"));</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 加载外部图像到位图</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function onComplete(event:Event):void</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建位图</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var image:Bitmap = Bitmap(loader.content);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = image.bitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(image);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.x = 20;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.y = 30;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，结果如图<span>19.2所示。</span></div>
<div align="left">图19.2&nbsp; 加载外部图像</div>
<div align="left"><strong>19.2&nbsp; </strong><strong>像素的处理</strong></div>
<div align="left">在<span>BitmapData类中，包含了一组用于像素处理的方法。使用这些方法可以处理单个像素，还可以处理像素数组。</span></div>
<div align="left"><strong>&nbsp;19.2.1&nbsp; </strong><strong>处理单个像素</strong></div>
<div align="left">处理单个像素用到的方法包括：<span>getPixel()、getPixel32()、setPixel()和setPixel32()。</span></div>
<div align="left"><strong>1</strong><strong>．</strong><strong>getPixel()</strong><strong>方法</strong></div>
<div align="left">getPixel()方法表示在指定的点获取位图的<span>RGB像素。此方法有两个参数，分别是指定点的横坐标和纵坐标。其语法格式如下所示：</span></div>
<div align="left">getPixel(x:int, y:int):uint</div>
<div align="left">参数的详细说明如下。</div>
<div align="left">&#8212;&nbsp; x：指定点的横坐标。</div>
<div align="left">&#8212;&nbsp; y：指定点的纵坐标。</div>
<div align="left">下面的示例使用<span>getPixel()方法获取点（1,1）的RGB像素值，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, false, 0xCC66FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var i:uint = bitmap.getPixel(1, 1);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 输出获取的像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(i.toString(16));</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，输出的效果如图<span>19.3所示。</span></div>
<div align="left">图19.3&nbsp; 使用getPixel()方法处理单个像素</div>
<div align="left"><strong>2</strong><strong>．</strong><strong>getPixel32()</strong><strong>方法</strong></div>
<div align="left">getPixel32()方法与<span>getPixel()方法类似，区别是getPixel32()方法返回一个ARGB的像素值。其中返回值包含了透明度的值。其语法格式如下所示：</span></div>
<div align="left">getPixel32(x:int, y:int):uint</div>
<div align="left">参数的详细说明如下。</div>
<div align="left">&#8212;&nbsp; x：指定点的横坐标。</div>
<div align="left">&#8212;&nbsp; y：指定点的纵坐标。</div>
<div align="left">下面的示例使用<span>getPixel32()方法，返回指定点的像素值，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, true, 0x50CC66FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var i:uint = bitmap.getPixel32(1, 1);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 输出获取的像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(i.toString(16));</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，输出的结果如图<span>19.4所示。</span></div>
<div align="left">图19.4&nbsp; 使用getPixel32()方法处理单个像素</div>
<div align="left"><strong>3</strong><strong>．</strong><strong>setPixel()</strong><strong>方法</strong></div>
<div align="left">setPixel()方法用来设置<span>BitmapData对象的单个像素。此方法有三个参数，前两个参数表示要设置单个像素的点，第三个参数color表示生成的像素RGB颜色。其语法格式如下所示：</span></div>
<div align="left">setPixel(x:int, y:int, color:uint):void</div>
<div align="left">参数的详细说明如下所示：</div>
<div align="left">&#8212;&nbsp; x：像素值会更改的像素的<span>x位置。</span></div>
<div align="left">&#8212;&nbsp; y：像素值会更改的像素的<span>y位置。</span></div>
<div align="left">&#8212;&nbsp; color：生成的像素的<span>RGB颜色。</span></div>
<div align="left">下面的示例使用<span>setPixel()方法，循环设置某些点的像素的RGB颜色，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, false, 0x000066FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(var i:uint = 0; i &lt; 300; i++)</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel(20, i, 0xFFFFFF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel(80, i, 0x000000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel(160, i, 0x00CC00);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建Bitmap类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var image:Bitmap = new Bitmap(bitmap);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置显示位置</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.x = 90;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.y = 50;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 增加到舞台</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(image);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，结果如图<span>19.5所示。</span></div>
<div align="left">图19.5&nbsp; setPixel()方法处理单个像素</div>
<div align="left"><strong>4</strong><strong>．</strong><strong>setPixel32()</strong><strong>方法</strong></div>
<div align="left">setPixel32()方法与<span>setPixel()方法类似，不同的是，setPixel32()方法是设置ARGB（其中A表示透明度）的像素值。此方法的前两个参数与setPixel()方法相同，最后一个参数表示生成的像素的ARGB颜色。其语法格式如下所示：</span></div>
<div align="left">setPixel32(x:int, y:int, color:uint):void</div>
<div align="left">参数的详细说明如下所示：</div>
<div align="left">&#8212;&nbsp; x：像素值会更改的像素的<span>x位置。</span></div>
<div align="left">&#8212;&nbsp; y：像素值会更改的像素的<span>y位置。</span></div>
<div align="left">&#8212;&nbsp; color：生成的像素的<span>ARGB颜色。</span></div>
<div align="left">下面的示例使用<span>setPixel32()方法，循环设置某些点的像素值，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, true, 0x700066FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(var i:uint = 0; i &lt; 300; i++)</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel32(20, i, 0x20FF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel32(21, i, 0x40FF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel32(22, i, 0x60FF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel32(23, i, 0x80FF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitmap.setPixel32(24, i, 0x00FF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建Bitmap类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var image:Bitmap = new Bitmap(bitmap);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置显示位置</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.x = 90;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.y = 50;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 增加到舞台</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(image);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，结果如图<span>19.6所示。</span></div>
<div align="left">图19.6&nbsp; 使用setPixel32()方法处理单个像素</div>
<div align="left"><strong>&nbsp;19.2.2&nbsp; </strong><strong>处理多个像素</strong></div>
<div align="left">ActionScript 3.0除了能处理单个像素外，还能处理多个像素。处理多个像素，一般是与字节数组有关的，把字节数组与像素的矩形区域相互转换。与处理多个元素有关的方法有两个：<span>getPixels()和setPixels()。</span></div>
<div align="left"><strong>1</strong><strong>．</strong><strong>getPixels()</strong><strong>方法</strong></div>
<div align="left">getPixels()方法将像素的矩形区域转换为一个字节数组并返回。<span>getPixels()方法有一个参数，表示当前BitmapData对象中的一个矩形区域。其语法格式如下所示：</span></div>
<div align="left">getPixels(rect:Rectangle):ByteArray</div>
<div align="left">下面的示例使用<span>getPixels()方法获取矩形区域的像素值，代码如下所示：</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.geom.Rectangle;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.utils.ByteArray;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData类</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bitmap:BitmapData = new BitmapData(400, 300, true, 0x700066FF);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bounds:Rectangle = new Rectangle(0, 0,bitmap.width, bitmap.height);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pixels:ByteArray = bitmap.getPixels(bounds);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace("像素数组的长度" + pixels.length);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace("以下是取几个元素的值：");</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(pixels[0]);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(pixels[4]);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(pixels[6]);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trace(pixels[10]);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，输出的结果如图<span>19.7所示。</span></div>
<div align="left">图19.7&nbsp; 使用getPixels()方法处理多个像素</div>
<div align="left"><strong>2</strong><strong>．</strong><strong>setPixels()</strong><strong>方法</strong></div>
<div align="left">setPixels()方法将字节数组转换为像素的矩形区域。其语法格式如下所示：</div>
<div align="left">&nbsp;setPixels(rect:Rectangle, inputByteArray:ByteArray):void</div>
<div align="left">参数说明如下。</div>
<div align="left">&#8212;&nbsp; rect：指定<span>BitmapData对象的矩形区域。</span></div>
<div align="left">&#8212;&nbsp; inputByteArray：一个字节数组对象，由要在矩形区域中使用的<span>32位未经过相乘的像素值组成。</span></div>
<div align="left">package&nbsp;</div>
<div align="left">{</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Sprite;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.Bitmap;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.display.BitmapData;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.geom.Rectangle;</div>
<div align="left">&nbsp;&nbsp;&nbsp; import flash.utils.ByteArray;</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp; public class BitmapExample extends Sprite</div>
<div align="left">&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /********************</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* 构造函数</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* */</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public function BitmapExample()</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建BitmapData对象</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bmd1:BitmapData = new BitmapData(200, 200, true, 0xFFCCCCCC);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bmd2:BitmapData = new BitmapData(200, 200, true, 0xFFFF0000);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建获取像素的矩形区域</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var rect:Rectangle = new Rectangle(20, 20, 150, 150);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bytes:ByteArray = bmd1.getPixels(rect);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置像素</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bytes.position = 0;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmd2.setPixels(rect, bytes);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 创建Bitmap对象</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bm1:Bitmap = new Bitmap(bmd1);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(bm1);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var bm2:Bitmap = new Bitmap(bmd2);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addChild(bm2);</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 设置位置</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm1.x = 50;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm1.y = 100;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm2.x = 260;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm2.y = 100;</div>
<div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp; }</div>
<div align="left">&nbsp;&nbsp;&nbsp;</div>
<div align="left">}</div>
<div align="left">编译代码并运行，结果如图<span>19.8所示。</span></div><br /><a href="http://leo398.blog.51cto.com/658992/341950">http://leo398.blog.51cto.com/658992/341950</a><img src ="http://www.cppblog.com/guojingjia2006/aggbug/148443.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2011-06-10 17:39 <a href="http://www.cppblog.com/guojingjia2006/archive/2011/06/10/148443.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>flex学习网站</title><link>http://www.cppblog.com/guojingjia2006/archive/2010/07/26/121322.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Mon, 26 Jul 2010 13:17:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2010/07/26/121322.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/121322.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2010/07/26/121322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/121322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/121322.html</trackback:ping><description><![CDATA[<div class="postTitle">
<a  href="http://www.blogjava.net/bolo/archive/2010/02/21/313567.html" id="viewpost1_TitleUrl" class="postTitle2">推荐几个不
错的Flex学习网站</a>
</div>
<span style="font-size: 10pt;"><span style="font-size: 9pt; font-family: 宋体;"><span style="font-size: 9pt;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">还在为学</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">找不到较好的资源发愁吗？大象给你推荐几个还不错的网站，保证不
是骗点击。^_^</span></span></span><span style="font-size: 9pt; font-family: 宋体;"><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">1、</span><a  href="http://www.adobe.com/cn/devnet/">http://www.adobe.com/cn/devnet/</a></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">adobe</span><span style="font-size: 9pt; font-family: 宋体;">中文开发网站，主页信息很多，我们关注其中的</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">和</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">ActionScript</span><span style="font-size: 9pt; font-family: 宋体;">。如果你喜欢桌面应用，</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">AIR</span><span style="font-size: 9pt; font-family: 宋体;">肯定有你感兴趣的东西。对于</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">的学习，官方网站当然是第一选择。</span></span></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">2、</span><a  href="http://blog.flexexamples.com/">http://blog.flexexamples.com/</a></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">例子的海洋，</span><span style="font-size: 9pt; font-family: 宋体;">主要以组件如何使用或者类的某某属性如何使用举例说明。</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">minidx</span><span style="font-size: 9pt; font-family: 宋体;">中的绝大部分都是翻译这里的文章。英文好的银就去这里看吧，里面已
经有很多关于</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex4</span><span style="font-size: 9pt; font-family: 宋体;">的
东东了。</span></span></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">3、</span><a  href="http://blog.minidx.com/">http://blog.minidx.com/</a></span><br>
<span style="font-size: 9pt; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">这网站的博主是一个很勤奋的家伙，里面有很丰富的关于</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">的实例，很有学习价值。主要是翻译</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">flexexamples</span><span style="font-size: 9pt; font-family: 宋体;">里面的文章，也有自己的原创。对于英文不好的朋友，这里就是你的
首选了。最近去看时发现，博主准备换服务器了，不知道域名变不变，大象会随时关注并更新滴。</span></span></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">4、</span><a  href="http://flex.org/">http://flex.org/</a></span><br>
<span style="font-size: 9pt; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">大名鼎鼎的</span><span style="font-size: 9pt;" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">权威网站，</span><span style="font-size: 9pt; font-family: 宋体;">集成了与</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">有关的大多数信息，最令人兴奋的是它无比丰富的组件库。只要你耐
心找，就可以找到你想要的。拿来使用是其次，学习高手的源码才是最重要的。</span></span></span><br>
<span style="font-size: 9pt; color: black; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">5、</span><a  href="http://ntt.cc/">http://ntt.cc/</a></span><br>
<span style="font-size: 9pt; color: black; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">国外的关于</span><span style="font-size: 9pt;" lang="EN-US">Flex</span><span style="font-size: 9pt; font-family: 宋体;">方面的又一个重量级网站，不说废话了，看了就知道。</span></span></span><br>
<span style="font-size: 9pt; color: black; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">6、</span><a  href="http://www.actionscriptclasses.com/">http://www.actionscriptclasses.com/</a></span><br>
<span style="font-size: 9pt; color: black; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">很全的一个类库网站，全世界的</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">Flexer</span><span style="font-size: 9pt; font-family: 宋体;">在这里共享自己的</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">AS</span><span style="font-size: 9pt; font-family: 宋体;">类。如果有不会写的，先来这里看看，很可能有人已经放上去了。呵
呵！</span></span></span><br>
<span style="font-size: 9pt; color: black; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">7、</span><a  href="http://www.9ria.com/html/index.html">http://www.9ria.com/html/index.html</a></span><br>
<span style="font-size: 9pt; color: black; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">天地会，国内非常大的一个</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">RIA</span><span style="font-size: 9pt; font-family: 宋体;">技术综合站点，也是开发者的交流平台，推荐大家经常去看看。</span></span></span><br>
<span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">8、</span><a  href="http://www.airia.cn/">www.airia.cn</a></span><br>
<span style="font-size: 9pt; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;"><span style="font-size: 9pt; font-family: 宋体;">艾睿网，</span><span style="font-size: 9pt; font-family: 宋体;">富</span><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">IT</span><span style="font-size: 9pt; font-family: 宋体;">技术开发者社区，有比较丰富的入门教程。</span></span></span><span style="font-size: 9pt; font-family: 宋体;"><span style="font-size: 9pt; font-family: 'courier new';" lang="EN-US">&nbsp; <br></span></span></span></span><img src ="http://www.cppblog.com/guojingjia2006/aggbug/121322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2010-07-26 21:17 <a href="http://www.cppblog.com/guojingjia2006/archive/2010/07/26/121322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>flex  获取 flickr 图片 </title><link>http://www.cppblog.com/guojingjia2006/archive/2010/07/20/120905.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Tue, 20 Jul 2010 14:10:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2010/07/20/120905.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/120905.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2010/07/20/120905.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/120905.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/120905.html</trackback:ping><description><![CDATA[这两天主要看了flex的cairngorm框架，顺便写了个用flex获取flickr网站的图片,其中不乏艰难的过程,第一个就是flickr库api和实际编译出来的有出入,其中Photo.as缺少farm就是一个明显，所以只能自己手工修改源码重新编译,网上讨论这个问题的比较少，不知道为什么，我找了好久才找到一篇关于这个的。还有一个问题就是大墙，其中网上有段这么描述:<br>
<div class="articalTitle"><span style="color: #888888;"><strong>最
近打开Flickr发现有些图片总是显示小红叉，开始以为是网速问题没有在意，昨天有个朋友说他存在Flickr上的图片都不能显示了，发觉情况不对劲
了。<br>今天看到了这篇帖子：</strong></span><a href="http://www.flickr.com/help/forum/zh-hk/117995/" target="_blank"><span style="color: #888888;"><strong>http://www.flickr.com/help/forum/zh-hk/117995/</strong></span></a><br><span style="color: #888888;"><strong>原来又是伟大的墙在作怪，这次的症状是所有的网通线路都无法
访问farm3.static.flickr.com和farm5.static.flickr.com这两个服务器，由于这次只是让域名无法解析，所以
最简单的解决办法是修改host文件，方法如下：<br>用记事本打开C:\Windows\System32\drivers\etc\hosts
这个文件，然后在文件最后追加两行:</strong></span></div>
<span style="color: #888888;"><strong></strong></span><span style="color: #888888;"><strong><img src="http://filer.blogbus.com/4552913/455291312659442693.png" alt="" border="0"></strong></span><br><span style="color: #888888;"><strong>然
后重启一下浏览器，我们亲爱的Flickr又复活了&nbsp; : )</strong></span><br><br>由于自己是网通的，图片是farm5服务器的，所以图片也显示不了，不过修改下host表就OK了<br><br>写这个的主要目的还是学习下cairgorm框架，学习他的MVC思想，目的算基本达到，flickr的问题实在有点烦，不过还是走过来了，下面是运行效果:<br><img alt="" src="http://www.cppblog.com/images/cppblog_com/guojingjia2006/ss.JPG" height="522" width="920"><br><br>有用的几个网址：<br>http://code.google.com/p/as3flickrlib/issues/detail?id=14#makechanges<br>http://www.flickr.com/services/api/<br>http://naramiki.blogbus.com/logs/57133710.html<br><br>最后附上flickr自己编译的库<br><a  href="http://www.cppblog.com/Files/guojingjia2006/flickr087.swc.rar">http://www.cppblog.com/Files/guojingjia2006/flickr087.swc.rar</a><br><br> <img src ="http://www.cppblog.com/guojingjia2006/aggbug/120905.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2010-07-20 22:10 <a href="http://www.cppblog.com/guojingjia2006/archive/2010/07/20/120905.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>flex (DragManager)</title><link>http://www.cppblog.com/guojingjia2006/archive/2010/06/15/117988.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Tue, 15 Jun 2010 12:44:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2010/06/15/117988.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/117988.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2010/06/15/117988.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/117988.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/117988.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;"><span style="font-family: courier new;">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;creationComplete="init()" layout="absolute"&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;mx:Style&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Application{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fontSize:12pt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;/mx:Style&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;mx:Script&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;![CDATA[</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; import mx.events.DragEvent;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; import mx.core.DragSource;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; import mx.managers.DragManager;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private function init():void{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private function dragIt(e:MouseEvent):void{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var myCanvas:Canvas=e.currentTarget as Canvas;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var dataSource:DragSource=new DragSource();</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataSource.addData(e.currentTarget,"obj");</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DragManager.doDrag(myCanvas,dataSource,e);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private function dragEnter(e:DragEvent):void{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var dropTarger:HBox=e.currentTarget as HBox;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DragManager.acceptDragDrop(dropTarger);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private function dragDrop(e:DragEvent):void{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var obj:Canvas=e.dragSource.dataForFormat("obj") as Canvas;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setCount(e.currentTarget as HBox,obj);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //var tb:HBox=(e.currentTarget as HBox);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //tb.addChild(obj);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //trace(e.currentTarget.toString());</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //myCanvas.addChild(e.currentTarget as DisplayObject);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private function setCount(hbox:HBox,cas:Canvas):void{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hbox.addChild(cas);</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(hbox.id=="sellList"){</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trace("sell");</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else{</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trace("buy");</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ]]&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;/mx:Script&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;mx:VBox id="myVBox" x="200" y="200"&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;mx:HBox id="sellList" backgroundColor="white" width="100" height="50" dragEnter="dragEnter(event)" dragDrop="dragDrop(event)"&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;mx:Canvas id="red" width="20" height="20"</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;borderStyle="solid" backgroundColor="red" mouseDown="dragIt(event)" /&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&lt;mx:Canvas id="green" width="20" height="20"</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;borderStyle="solid" backgroundColor="green" mouseDown="dragIt(event)" /&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&lt;mx:Canvas id="blue" width="20" height="20"</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;borderStyle="solid" backgroundColor="blue" mouseDown="dragIt(event)" /&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&lt;/mx:HBox&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp;&lt;mx:HBox id="buyList" backgroundColor="white"</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp; borderStyle="solid" width="100" height="100" dragEnter="dragEnter(event)" dragDrop="dragDrop(event)" /&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp; </span><br style="font-family: courier new;"><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &nbsp; &lt;/mx:VBox&gt;</span><br style="font-family: courier new;"><span style="font-family: courier new;">&lt;/mx:Application&gt;</span><br></span><span style="color: #000000;"><br></span></div>
<img src="http://www.cppblog.com/images/cppblog_com/guojingjia2006/e.jpg" border="0"><br>DragManager小应用<br> <img src ="http://www.cppblog.com/guojingjia2006/aggbug/117988.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2010-06-15 20:44 <a href="http://www.cppblog.com/guojingjia2006/archive/2010/06/15/117988.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Flex 鼠标事件触发顺序</title><link>http://www.cppblog.com/guojingjia2006/archive/2010/01/11/105375.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Mon, 11 Jan 2010 02:01:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2010/01/11/105375.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/105375.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2010/01/11/105375.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/105375.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/105375.html</trackback:ping><description><![CDATA[roll_over roll_out事件根据范围判定<br>mouse_down mouse_out 根据对象判定<br>mouse_down mouse_out 先于单击事件触发<br>双击事件触发时 mouse_down,mouse_out触发二次，单击事件触发一次，第二次单击时不处罚click<br><br><img src ="http://www.cppblog.com/guojingjia2006/aggbug/105375.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2010-01-11 10:01 <a href="http://www.cppblog.com/guojingjia2006/archive/2010/01/11/105375.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>