BitmapData.copyChannel() method copies a channel from a source image and pastes it into a target image’s alpha channel. You can control the transparecy of an image by manipulating the image’s alpha channel with a source image.
The following code adds fading border effect to an image.
BitmapData.copyChannel() 메소드를 사용하여, 원하는 이미지의 특정 채널을 대상 이미지의 알파채널로 복사할 수 있습니다. 이것을 사용하면 소스 이미지를 알파채널로 사용하여 이미지의 투명도를 제어할 수 있습니다.
아래 코드는 이미지의 테두리를 부드럽게 빼는 효과를 구현한 것입니다.
/*
* This work is licensed under a Creative Commons Attribution 3.0 License.
* http://creativecommons.org/licenses/by/3.0/
*/
/*
* FadeImageBorder
* FadeImageBorder class adds the fading border effect to an image
*
* @author: Han Sanghun (http://hangunsworld.com/blog)
* @last modified: 2007-05-22
* @language version: ActionScript 3.0
*/
package{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class FadeImageBorder extends MovieClip{
// Fade Source
private var fade_bd:BitmapData;
// Fade Copy
private var fadeCopy_bd:BitmapData;
// Original Image
private var origin_bd:BitmapData;
private var origin_bmp:Bitmap;
// Result Image
private var result_bd:BitmapData;
private var result_bmp:Bitmap;
/*
* FadeImageBorder constructor
*/
public function FadeImageBorder(){
// Original image size
var wid:uint = 400;
var hgt:uint = 300;
// Original/Result BitmapData
origin_bd = new ImageSample(wid, hgt);
result_bd = new BitmapData(wid, hgt, true, 0×00000000);
result_bd.draw(origin_bd);
// Fade Effect BitmapData
fade_bd = new FadeBorderSource(500, 500);
fadeCopy_bd = new BitmapData(wid, hgt, true, 0×00000000);
// create fade_bmp for resizing
var fade_bmp:Bitmap = new Bitmap(fade_bd);
// create temporary sprite
var fade_sp:Sprite = new Sprite();
fade_sp.addChild(fade_bmp);
// resize fade_bmp to fit the source image
fade_bmp.width = wid;
fade_bmp.height = hgt;
// draw to fadeCopy_bd
fadeCopy_bd.draw(fade_sp);
// Copy alpha channel
var rect:Rectangle = new Rectangle(0, 0, wid, hgt);
var pnt:Point = new Point(0, 0);
result_bd.copyChannel(fadeCopy_bd, rect, pnt, BitmapDataChannel.BLUE, BitmapDataChannel.ALPHA);
// Add to stage
result_bmp = new Bitmap(result_bd);
addChild(result_bmp);
origin_bmp = new Bitmap(origin_bd);
addChild(origin_bmp);
result_bmp.x = result_bmp.y = origin_bmp.x = origin_bmp.y = 25;
// Click event
stage.addEventListener(MouseEvent.CLICK, mouseClicked);
}
/*
* mouseClicked
* Add/remove the fade border effect.
*/
private function mouseClicked(evt:MouseEvent):void{
origin_bmp.visible = !origin_bmp.visible;
}
}
}
코멘트
2의 “[AS3] Fading Border Effect”에 대한 답변
흐흐.. 멋진데~
이거 퍼가도 되지.. ^^.
나도 김태희 좋앙~~
퍼가는 거야 자유지…
단, CC 라이센스 라는거…
ps. 김태희, 바나나 CF에서 넘 이쁘게 나왔어 ^0^
그거 바탕화면 같은거 없나