More Games - PAINONE

Android games

sites.google.com

Flex 캡쳐 서버 전송
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.graphics.ImageSnapshot;
            import mx.rpc.http.HTTPService;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.graphics.codec.JPEGEncoder;
            import flash.display.BitmapData;
            import mx.controls.Alert;
 
            /**
             * 화면 캡쳐
             */
            private function CaptureImg():String {
                var bitmapData:BitmapData       = new BitmapData(img.width, img.height);
                    bitmapData.draw(img);
 
                var imageSnapshot:ImageSnapshot = ImageSnapshot.captureImage(bitmapData, 0, new JPEGEncoder());
                return ImageSnapshot.encodeImageAsBase64(imageSnapshot);
            }
 
            /**
             * 서버에 데이타 전송
             */
            public function HttpServerce():void {
                var httpData:HTTPService        = new HTTPService();
                    httpData.url                = "http://localhost/upload.php";
                    httpData.addEventListener(ResultEvent.RESULT,   Result);
                    httpData.addEventListener(FaultEvent.FAULT,     Fault);
                    httpData.useProxy           = false;
                    httpData.method             = "POST";
                    httpData.request.imageData  = CaptureImg();
                    httpData.request.imageFormat= "jpg";
                    httpData.send();
            }
 
            /**
             * 서버 전송 성공 처리
             */
            private function Result(event:ResultEvent):void {
                Alert.show(event.result.toString());           
            }
             
            /**
             * 실패처리
             */
            private function Fault(event:FaultEvent):void {
                Alert.show(event.toString());
            }
        ]]>
    </mx:Script>
    <mx:Image id="img"  source=""/>
    <mx:Button label="캡쳐/전송" click="HttpServerce()"/>
</mx:Application>
]]>
Flex 지정 영역 캡쳐 서버 전송
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.graphics.ImageSnapshot;
            import mx.rpc.http.HTTPService;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.graphics.codec.JPEGEncoder;
            import flash.display.BitmapData;
            import mx.controls.Alert;
 
            /**
             * 화면 캡쳐
             */
            private function CaptureImg():String {
                var bitmapData1:BitmapData  = new BitmapData(img.width, img.height);
                    bitmapData1.draw(img);
                var bitmapData2:BitmapData  = new BitmapData(100, 100);
                var rect:Rectangle          = new Rectangle(0, 0, 100, 100);
                var pt:Point                = new Point(0, 0);
                    bitmapData2.copyPixels(bitmapData1, rect, pt);
 
                var imageSnapshot:ImageSnapshot = ImageSnapshot.captureImage(bitmapData, 0, new JPEGEncoder());
                return ImageSnapshot.encodeImageAsBase64(imageSnapshot);
            }
 
            /**
             * 서버에 데이타 전송
             */
            public function HttpServerce():void {
                var httpData:HTTPService        = new HTTPService();
                    httpData.url                = "http://localhost/upload.php";
                    httpData.addEventListener(ResultEvent.RESULT,   Result);
                    httpData.addEventListener(FaultEvent.FAULT,     Fault);
                    httpData.useProxy           = false;
                    httpData.method             = "POST";
                    httpData.request.imageData  = CaptureImg();
                    httpData.request.imageFormat= "jpg";
                    httpData.send();
            }
 
            /**
             * 서버 전송 성공 처리
             */
            private function Result(event:ResultEvent):void {
                Alert.show(event.result.toString());           
            }
             
            /**
             * 실패처리
             */
            private function Fault(event:FaultEvent):void {
                Alert.show(event.toString());
            }
        ]]>
    </mx:Script>
    <mx:Image id="img"  source=""/>
    <mx:Button label="캡쳐/전송" click="HttpServerce()"/>
</mx:Application>
]]>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
    $imageData  = $_POST["imageData"];
    $imageFormat= $_POST["imageFormat"];
 
    $updir      = $_SERVER[DOCUMENT_ROOT]."/myStyle/upload/";
    $datetime   = date(Ymdhis);
    $filename   = $updir.$datetime.".".$imageFormat;
 
    if(!file_exists($filename)) {
        $fp = fopen($filename, "w");
        fwrite($fp, base64_decode($imageData));
    } else {
        $datetime++;
        do {
            $filename = $updir.$datetime.".".$imageFormat;
        } while(file_exists($filename));
        $fp = fopen($filename, "w");
        fwrite($fp, base64_decode($imageData));
    }
?>
 

More Games - PAINONE

Android games

sites.google.com

+ Recent posts