액션 2 장 : ActionScript 2의
, 당신은 내가 my answer for this question에 사용되는 PHP 스크립트와 같은 서버 측 스크립트를 사용하여 이미지를 저장해야합니다.
액션 스크립트 3 : 액션 스크립트 3
상황이 FileReference
우리의 컴퓨터에 직접 save 우리에게 파일을 수있는 기능을 제공하기 때문에 더 쉽습니다.
이미지를 jpg 또는 png 파일로 저장하려면 as3corelib 라이브러리에 포함 된 JPGEncoder
및 PNGEncoder
을 사용하면됩니다. here에서 다운로드 한 다음 파일> ActionScript 설정 ...> 라이브러리 경로에서 프로젝트에 포함시킨 다음 을 누르십시오. SWC 파일으로 이동하여 as3corelib.swc 다운로드 파일을 선택하십시오. 그럼 당신은 다음과 같이 수행 할 수 있습니다
// in my stage, I have 2 buttons : btn_save_jpg and btn_save_png, and a MovieClip : movie_clip
import com.adobe.images.JPGEncoder;
import com.adobe.images.PNGEncoder;
btn_save_jpg.addEventListener(MouseEvent.CLICK, save_img);
btn_save_png.addEventListener(MouseEvent.CLICK, save_img);
function save_img(e:MouseEvent):void {
// verify which button is pressed using its name
var is_jpg:Boolean = (e.currentTarget.name).substr(-3, 3) == 'jpg';
// you can also write it : var is_jpg:Boolean = e.currentTarget === btn_save_jpg;
// create our BitmapData and draw within our movie_clip MovieClip
var bmd_src:BitmapData = new BitmapData(movie_clip.width, movie_clip.height)
bmd_src.draw(movie_clip);
if(is_jpg){
// if it's the btn_save_jpg button which is pressed, so create our JPGEncoder instance
// for the btn_save_png button, we don't need to create an instance of PNGEncoder
// because PNGEncoder.encode is a static function so we can call it directly : PNGEncoder.encode()
var encoder:JPGEncoder = new JPGEncoder(90);
// 90 is the quality of our jpg, 0 is the worst and 100 is the best
}
// get encoded BitmapData as a ByteArray
var stream:ByteArray = is_jpg ? encoder.encode(bmd_src) : PNGEncoder.encode(bmd_src);
// open the save dialog to save our image
var file:FileReference = new FileReference();
file.save(stream, 'snapshot_' + getTimer() + (is_jpg ? '.jpg' : '.png'));
}
을 당신이 AS3 (또는 심지어 AS2) 코드에 대한 질문이있는 경우, 코멘트 영역을 사용을 주저하지 않습니다.
희망이 도움이 될 수 있습니다.
감사합니다 akmozo, 나는 두 가지 제안을 시도 할 것입니다. –