TheOtherSideDoor
2010. 8. 13. 13:14
2010. 8. 13. 13:14
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" usePreloader="false" horizontalScrollPolicy="off" verticalScrollPolicy="off" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"> <mx:Script> <![CDATA[
import mx.core.UIComponent; import com.adobe.images.PNGEncoder;
private function getBitmapData( target : UIComponent ) : BitmapData { var bd : BitmapData = new BitmapData( target.width, target.height ); var m : Matrix = new Matrix(); bd.draw( target, m ); return bd; } public function CapImage():void { var bd : BitmapData = getBitmapData( UIComponent( imgPanel ) ); targetImage.source = new Bitmap( bd ); } public function SaveAsPng():void { var url:String = "print.php"; var request:URLRequest = new URLRequest(url); var imageData:ByteArray = PNGEncoder.encode(getBitmapData(UIComponent( imgPanel )));
var urlR:URLRequest = new URLRequest(url); var boundary:String = '------wsos------'; urlR.contentType = 'multipart/form-data; boundary='+boundary; boundary = '--'+boundary; var data:ByteArray = new ByteArray; data.writeUTFBytes(boundary+'\r\n'); // start new part data.writeUTFBytes('Content-Disposition: form-data; name="file_upload"; filename="image.png"\r\n'); data.writeUTFBytes('Content-Type: image/png\r\n'); data.writeUTFBytes('Content-Transfer-Encoding: binary\r\n\r\n'); // write image data data.writeBytes(imageData); // terminate part data.writeUTFBytes('\r\n'+boundary+'\r\n'); // start a new part if you want to send other POST variables data.writeUTFBytes('Content-Disposition: form-data; name="test"\r\n\r\n'); data.writeUTFBytes('wsos'); data.writeUTFBytes('\r\n'+boundary+'\r\n'); urlR.data = data; urlR.method = URLRequestMethod.POST; navigateToURL(urlR,"_self"); } ]]> </mx:Script> <mx:VBox width="100%" height="100%"> <mx:Image id="targetImage" width="100%" height="50%"/> <mx:HBox width="100%"> <mx:Button label="화면캡쳐" click="CapImage();"/> <mx:Button label="이미지로 저장(PNG)" click="SaveAsPng();"/> </mx:HBox> <mx:Panel id="imgPanel" width="100%" height="50%" layout="absolute" title="이미지저장"> <mx:TextArea top="10" bottom="10" left="10" right="10"/> </mx:Panel> </mx:VBox> </mx:Application>
|
print.php
<? /* $result = array_merge($HTTP_GET_VARS,$HTTP_POST_VARS); print_r($result); print_r($HTTP_POST_FILES); */
$files = $HTTP_POST_FILES["file_upload"];
if($files){
Header("Content-type:application/octet-stream"); Header("Content-Length:".$files["size"]); Header("Content-Disposition:attachment;filename=".$files["name"]); Header("Content-type:file/unknown");
//Header("Content-type:image/png");
Header("Pragma: no-cache"); Header("Expires: 0");
$filename = $files["tmp_name"]; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize ($filename));
echo $contents; fclose ($fd); }
?> |
2. 데모
3. 참고