2011년 3월 10일 목요일
pg 인코더. 사용해서.. bitmap -> byteArray로 서버에 전송하기 ( 첨부파일 : 서버에 저장하는 샘플 ) [출처] jpg 인코더. 사용해서.. bitmap -> byteArray로 서버에 전송하기 ( 첨부파일 : 서버에 저장하는 샘플 )|작성자 위니
First Things First
Before we get started, make sure to grab the ActionScript 3 Core Library. The Core Library contains several classes and utilities that make it easy to do things such as MD5 hashing, date formatting, and image encoding to name a few. Once you have the library, just drop it into your classes folder and you are ready to go. Now we can import the JPGEncoder.
import com.adobe.images.JPGEncoder;
Encoding the MovieClip
In this example, we are going to assume that our MovieClip of interest is named sketch_mc. In order to make use of the JPEGEncoder, our MovieClip needs to become a bitmap. To do this, we are going to use the BitmapData class. The contructor for this class requires two arguments: width and height. Since we want our jpeg to be the same size as sketch_mc, we use it’s width and height properties. Then by using sketch_mc as an argument, the draw method draws our MovieClip on to the bitmap.
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);
Now that sketch_mc is in bitmap form, we can use the JPGEncoder. When creating a new instance of this class, you can set the level of compression by passing in a number from 1 - 100. Then to create our jpeg, we call the encode method and use our BitmapData instance as the argument. The encode method returns the jpeg in the form of a ByteArray, which is simply an AS3 class that makes working with binary data a little easier.
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
From the Flash Player to the Hard Drive
ActionScript 3 has done all the work neccessary to turn our MovieClip into a jpeg, but it needs a little help in making it available to download. To make this happen, we will need to post our ByteArray to a server side script using the URLRequest class. Since we are posting binary data, we must set the content-type to “application/octet-stream”. It is also important to note that the file being downloaded will need a name, so we pass that to our server side script as a query string.
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
php 소스 엮인글 -
http://blog.naver.com/kjhbond/50082537619 - 서버에 저장하는 php 구문
http://blog.naver.com/kjhbond/50082538671 - 로컬 컴퓨터에 저장하는 php 구문 ( 테스트 브라우저 : 크롬 )
2011년 3월 3일 목요일
2011년 2월 28일 월요일
smsx.cab을 이용한 웹페이지 프린트 설정하기
<body> 안에 아래 코드 삽입
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/include/js/smsx.cab#Version=6,3,439,30"> </object>
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/include/js/smsx.cab#Version=6,3,439,30"> </object>
오브젝트 안에 버젼정보 맞춰주고 다운받은 파일을 웹서버에 올리고 경로를 맞춰줌
<a href="#" onclick="printArea()">프린트 하기</a>
<script type="text/javascript">
function printArea() {
factory.printing.header = ""; //머릿말 설정
factory.printing.footer = ""; // 꼬릿말 설정
factory.printing.portrait = false; //false = 가로 출력 , true = 세로 출력
factory.printing.leftMargin = 0.0; // 좌측여백
factory.printing.topMargin = 0.0; // 위 여백
factory.printing.rightMargin = 0.0; // 우측여백
factory.printing.bottomMargin = 0.0; // 아래여백
factory.printing.Print(false, window);
function printArea() {
factory.printing.header = ""; //머릿말 설정
factory.printing.footer = ""; // 꼬릿말 설정
factory.printing.portrait = false; //false = 가로 출력 , true = 세로 출력
factory.printing.leftMargin = 0.0; // 좌측여백
factory.printing.topMargin = 0.0; // 위 여백
factory.printing.rightMargin = 0.0; // 우측여백
factory.printing.bottomMargin = 0.0; // 아래여백
factory.printing.Print(false, window);
// false = 프린트 대화창안열음 , true = 대화창 열음
// window = 윈도우 전체 출력 , 또는 프레임명을 넣어서 프레임을 출력한다.
}
// window = 윈도우 전체 출력 , 또는 프레임명을 넣어서 프레임을 출력한다.
}
</script>
2011년 2월 22일 화요일
피드 구독하기:
글 (Atom)