플래쉬가 8.0이 나오면서 BitmapData를 사용이 가능해지면서 비트맵 데이터를 손쉽게 제어를 할수있게 되었습니다.(사실 CPU점유율이 너무 높기 때문에 거의 사용이 불가능 하긴 합니다...-_-;;)
BitmapData를 이용해서 플래쉬의 화면에 표시되는 내용을 php를 이용해서 외부에 서버에 저장하는게 가능하더군요...머 하려고 한다면 다른 언어도 가능은 하겠지만 제가 서버관련 언어는 모르기에...^^;;;
원문은 이 사이트에 가시면 보실수가 있습니다. 그리고 샘플 자료가 다운로드 가능하니 가셔서 한번 둘러봐 보시는것도 좋을듯 합니다.
http://www.flash-db.com/Tutorials/snapshot/snapshot.php?page=1
영어랑 워낙 친하지 못해서 있다는 정도만 알아두다 요즘은 한가한 관계로 좀 잠깐 보게 되었습니다.
코드를 보고 제 나름대로 생각한 것만 적어보도록 하겠습니다.(제대로 해석이 안되기 때문에 나름 제가 생각한대로 적는 거니까 이대로 생각하시고 작업하시다 잘못되도 책임은 못져드립니다...-_-;;;)
********************************************************************************************************************************
capture란 이함수는 이미지를 캡쳐를 실행하게 됩니다.
function capture(nr){
this["snapshot"+nr] = new BitmapData(output_vid._width,output_vid._height);
//draw the current state of the Video object into
//the bitmap object with no transformations applied
this["snapshot"+nr].draw(output_vid,new Matrix());
var t:MovieClip = createEmptyMovieClip("bitmap_mc"+nr,nr);
t._x = 350; t._y = 10+(nr*130); t._xscale = t._yscale = 50
//display the specified bitmap object inside the movie clip
//t라는 변수에 bitmap_mc를 만들어서 이미지를 저장하게 됩니다. nr로 들어오는 파라미터로 필터
//의 종류를 선택하게 됩니다.
t.attachBitmap(this["snapshot"+nr],1);
var filterArray = new Array(myFilters[nr])
t.filters = filterArray
attachMovie("print_but", "bot"+nr, 100+nr, {_x:t._x+t._width+50, _y:t._y+t._height/2})
}
output함수를 실행하게 되면은 이미지의 정보값을 배열에 저장후 서버쪽으로 값을 보내는 함수를 실행하게 됐니다
//
function output(who){
//preloader visible
preloader._visible = true
//Here we will copy pixels data
var pixels:Array = new Array()
//Create a new BitmapData
var snap = new BitmapData(who.width, who.height);
//Matrix to scale the new image
myMatrix = new Matrix();
myMatrix.scale(0.5, 0.5)
//Copy video image
snap.draw(who, myMatrix);
//Uncoment this line if you want to apply filters instead of just capturing source
// results should be adjusted based on your library version, not recomended
//snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr])
var w:Number = snap.width, tmp
var h:Number = snap.height
//Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar
//엔터 프레임이 도는 동안 픽셀값들의 데이터 값을 저장하게 됩니다.
var a:Number = 0
this.onEnterFrame = function(){
for(var b=0; b<=h; b++){
tmp = snap.getPixel32(a, b).toString(16)
//trace(tmp)
pixels.push(tmp.substr(1))
}
perc = int((a*100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a>w){ //Finish capturing
preloader._visible = false
sendData(pixels, h, w)
//free memory
snap.dispose()
delete this.onEnterFrame
}
}
}
//
output의 실행이 완료되면 sendData를 호출하게 됩니다.파라미터를 받아서 show.php로 픽셀값들과 이미지의 사이즈 정보를 보냅니다.
function sendData(pixels:Array, h:Number, w:Number){
//Create the LoadVars object and pass data to PHP script
var output:LoadVars = new LoadVars()
output.img = pixels.toString()
output.height = h
output.width = w
//The page (and this movie itself) should be in a server to work
output.send("show.php", "output", "POST")
}
여기까지가 플래쉬에서 처리를 하게 되고 이후는 서버언어에서 처리를 하게 됩니다.
사실 저도 이런 방식으로 이미지를 저장한다는것은 음 생각해 내기가 어려웠을듯 하고 php에서 이미지 값을 가져와서 이미지를 그려낼수 있다는것을 알지 못했기때문에 생각조차 못했을수도 있겠네요 개발자 분들이 그러시는데 속도가 느려서 사용을 할수 있을지 모르겠다고 하시는데 일단 가능하다는건 알았으니....ㅎㅎ
서버에 이미지값을 저장 했다가 나중에 값을 받아서 다시 플래쉬에서 그려주는것도 가능하고 찾아보면 활용을 할수 있는 여지가 있을듯 합니다. 단 느리다는건 감안을 하셔야 할것 같습니다.1024*768사이즈의 월페이퍼 같은건 음.....^^;;;;
마지막으로 php내용입니다. 지금까지의 내용은 원문을 보시면 동일합니다....^^
//If GD library is not installed, say sorry
if(!function_exists("imagecreate")) die("Sorry, you need GD library to run this example");
//Capture Post data
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
//Allocate image
$image=(function_exists("imagecreatetruecolor"))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height);
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
while(strlen($data[$i]) < 6) $data[$i] = "0" . $data[$i];
$r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
$g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
$b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
$color = ($r << 16) | ($g << 8) | $b;
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel ( $image , $x , $y , $color );
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );
imagedestroy( $image );
}
BitmapData를 이용해서 플래쉬의 화면에 표시되는 내용을 php를 이용해서 외부에 서버에 저장하는게 가능하더군요...머 하려고 한다면 다른 언어도 가능은 하겠지만 제가 서버관련 언어는 모르기에...^^;;;
원문은 이 사이트에 가시면 보실수가 있습니다. 그리고 샘플 자료가 다운로드 가능하니 가셔서 한번 둘러봐 보시는것도 좋을듯 합니다.
http://www.flash-db.com/Tutorials/snapshot/snapshot.php?page=1
영어랑 워낙 친하지 못해서 있다는 정도만 알아두다 요즘은 한가한 관계로 좀 잠깐 보게 되었습니다.
코드를 보고 제 나름대로 생각한 것만 적어보도록 하겠습니다.(제대로 해석이 안되기 때문에 나름 제가 생각한대로 적는 거니까 이대로 생각하시고 작업하시다 잘못되도 책임은 못져드립니다...-_-;;;)
********************************************************************************************************************************
capture란 이함수는 이미지를 캡쳐를 실행하게 됩니다.
function capture(nr){
this["snapshot"+nr] = new BitmapData(output_vid._width,output_vid._height);
//draw the current state of the Video object into
//the bitmap object with no transformations applied
this["snapshot"+nr].draw(output_vid,new Matrix());
var t:MovieClip = createEmptyMovieClip("bitmap_mc"+nr,nr);
t._x = 350; t._y = 10+(nr*130); t._xscale = t._yscale = 50
//display the specified bitmap object inside the movie clip
//t라는 변수에 bitmap_mc를 만들어서 이미지를 저장하게 됩니다. nr로 들어오는 파라미터로 필터
//의 종류를 선택하게 됩니다.
t.attachBitmap(this["snapshot"+nr],1);
var filterArray = new Array(myFilters[nr])
t.filters = filterArray
attachMovie("print_but", "bot"+nr, 100+nr, {_x:t._x+t._width+50, _y:t._y+t._height/2})
}
output함수를 실행하게 되면은 이미지의 정보값을 배열에 저장후 서버쪽으로 값을 보내는 함수를 실행하게 됐니다
//
function output(who){
//preloader visible
preloader._visible = true
//Here we will copy pixels data
var pixels:Array = new Array()
//Create a new BitmapData
var snap = new BitmapData(who.width, who.height);
//Matrix to scale the new image
myMatrix = new Matrix();
myMatrix.scale(0.5, 0.5)
//Copy video image
snap.draw(who, myMatrix);
//Uncoment this line if you want to apply filters instead of just capturing source
// results should be adjusted based on your library version, not recomended
//snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr])
var w:Number = snap.width, tmp
var h:Number = snap.height
//Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar
//엔터 프레임이 도는 동안 픽셀값들의 데이터 값을 저장하게 됩니다.
var a:Number = 0
this.onEnterFrame = function(){
for(var b=0; b<=h; b++){
tmp = snap.getPixel32(a, b).toString(16)
//trace(tmp)
pixels.push(tmp.substr(1))
}
perc = int((a*100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a>w){ //Finish capturing
preloader._visible = false
sendData(pixels, h, w)
//free memory
snap.dispose()
delete this.onEnterFrame
}
}
}
//
output의 실행이 완료되면 sendData를 호출하게 됩니다.파라미터를 받아서 show.php로 픽셀값들과 이미지의 사이즈 정보를 보냅니다.
function sendData(pixels:Array, h:Number, w:Number){
//Create the LoadVars object and pass data to PHP script
var output:LoadVars = new LoadVars()
output.img = pixels.toString()
output.height = h
output.width = w
//The page (and this movie itself) should be in a server to work
output.send("show.php", "output", "POST")
}
여기까지가 플래쉬에서 처리를 하게 되고 이후는 서버언어에서 처리를 하게 됩니다.
사실 저도 이런 방식으로 이미지를 저장한다는것은 음 생각해 내기가 어려웠을듯 하고 php에서 이미지 값을 가져와서 이미지를 그려낼수 있다는것을 알지 못했기때문에 생각조차 못했을수도 있겠네요 개발자 분들이 그러시는데 속도가 느려서 사용을 할수 있을지 모르겠다고 하시는데 일단 가능하다는건 알았으니....ㅎㅎ
서버에 이미지값을 저장 했다가 나중에 값을 받아서 다시 플래쉬에서 그려주는것도 가능하고 찾아보면 활용을 할수 있는 여지가 있을듯 합니다. 단 느리다는건 감안을 하셔야 할것 같습니다.1024*768사이즈의 월페이퍼 같은건 음.....^^;;;;
마지막으로 php내용입니다. 지금까지의 내용은 원문을 보시면 동일합니다....^^
//If GD library is not installed, say sorry
if(!function_exists("imagecreate")) die("Sorry, you need GD library to run this example");
//Capture Post data
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
//Allocate image
$image=(function_exists("imagecreatetruecolor"))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height);
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
while(strlen($data[$i]) < 6) $data[$i] = "0" . $data[$i];
$r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
$g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
$b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
$color = ($r << 16) | ($g << 8) | $b;
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel ( $image , $x , $y , $color );
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );
imagedestroy( $image );
}


::: 사람과 사람의 교감! 人터넷의 첫 시작! 댓글을 달아주세요! :::