当前位置:
凯发ag旗舰厅登录网址下载 >
编程语言
> php
>内容正文
php
flex php截图demo -凯发ag旗舰厅登录网址下载
凯发ag旗舰厅登录网址下载
收集整理的这篇文章主要介绍了
flex php截图demo
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在flex中使用了两种方案来处理图片:
一、直接将bytearray转为bitmap通过loader(flash.display.loader)显示在舞台上;
二、将bytearray调用将三方方法(base64),做为字符串传给php,php使用base64_decode再将图片进行保存
demo效果图:
操作步骤:
1、点击“载入图片”,然后点击“截取图片”,在容器中拉出一条线,之后将三确定一个红色矩形框
2、点击“保存图片”,提交后台php,并在舞台中生成一张当前截图
3、后台保存的文件格式为当前“年月日_时分秒_img.png”
flex代码:
1: "1.0" encoding="utf-8"?> 2:引用的base64.as(存放于com.dynamicflash.util包中)
1: /* 2: base64 - 1.1.0 3: 4: 凯发ag旗舰厅登录网址下载 copyright (c) 2006 steve webster 5: 6: permission is hereby granted, free of charge, to any person obtaining a copy of 7: this software and associated documentation files (the "software"), to deal in 8: the software without restriction, including without limitation the rights to 9: use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10: the software, and to permit persons to whom the software is furnished to do so, 11: subject to the following conditions: 12: 13: the above 凯发ag旗舰厅登录网址下载 copyright notice and this permission notice shall be included in all 14: copies or substantial portions of the software. 15: 16: the software is provided "as is", without warranty of any kind, express or 17: implied, including but not limited to the warranties of merchantability, fitness 18: for a particular purpose and noninfringement. in no event shall the authors or 19: 凯发ag旗舰厅登录网址下载 copyright holders be liable for any claim, damages or other liability, whether 20: in an action of contract, tort or otherwise, arising from, out of or in 21: connection with the software or the use or other dealings in the software. 22: */ 23: 24: package com.dynamicflash.util { 25: 26: import flash.utils.bytearray; 27: 28: public class base64 { 29: 30: private static const base64_chars:string = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 /="; 31: 32: public static const version:string = "1.0.0"; 33: 34: public static function encode(data:string):string { 35: // convert string to bytearray 36: var bytes:bytearray = new bytearray(); 37: bytes.writeutfbytes(data); 38: 39: // return encoded bytearray 40: return encodebytearray(bytes); 41: } 42: 43: public static function encodebytearray(data:bytearray):string { 44: // initialise output 45: var output:string = ""; 46: 47: // create data and output buffers 48: var databuffer:array; 49: var outputbuffer:array = new array(4); 50: 51: // rewind bytearray 52: data.position = 0; 53: 54: // while there are still bytes to be processed 55: while (data.bytesavailable > 0) { 56: // create new data buffer and populate next 3 bytes from data 57: databuffer = new array(); 58: for (var i:uint = 0; i < 3 && data.bytesavailable > 0; i ) { 59: databuffer[i] = data.readunsignedbyte(); 60: } 61: 62: // convert to data buffer base64 character positions and 63: // store in output buffer 64: outputbuffer[0] = (databuffer[0] & 0xfc) >> 2; 65: outputbuffer[1] = ((databuffer[0] & 0x03) << 4) | ((databuffer[1]) >> 4); 66: outputbuffer[2] = ((databuffer[1] & 0x0f) << 2) | ((databuffer[2]) >> 6); 67: outputbuffer[3] = databuffer[2] & 0x3f; 68: 69: // if data buffer was short (i.e not 3 characters) then set 70: // end character indexes in data buffer to index of '=' symbol. 71: // this is necessary because base64 data is always a multiple of 72: // 4 bytes and is basses with '=' symbols. 73: for (var j:uint = databuffer.length; j < 3; j ) { 74: outputbuffer[j 1] = 64; 75: } 76: 77: // loop through output buffer and add base64 characters to 78: // encoded data string for each character. 79: for (var k:uint = 0; k < outputbuffer.length; k ) { 80: output = base64_chars.charat(outputbuffer[k]); 81: } 82: } 83: 84: // return encoded data 85: return output; 86: } 87: 88: public static function decode(data:string):string { 89: // decode data to bytearray 90: var bytes:bytearray = decodetobytearray(data); 91: 92: // convert to string and return 93: return bytes.readutfbytes(bytes.length); 94: } 95: 96: public static function decodetobytearray(data:string):bytearray { 97: // initialise output bytearray for decoded data 98: var output:bytearray = new bytearray(); 99: 100: // create data and output buffers 101: var databuffer:array = new array(4); 102: var outputbuffer:array = new array(3); 103: 104: // while there are data bytes left to be processed 105: for (var i:uint = 0; i < data.length; i = 4) { 106: // populate data buffer with position of base64 characters for 107: // next 4 bytes from encoded data 108: for (var j:uint = 0; j < 4 && i j < data.length; j ) { 109: databuffer[j] = base64_chars.indexof(data.charat(i j)); 110: } 111: 112: // decode data buffer back into bytes 113: outputbuffer[0] = (databuffer[0] << 2) ((databuffer[1] & 0x30) >> 4); 114: outputbuffer[1] = ((databuffer[1] & 0x0f) << 4) ((databuffer[2] & 0x3c) >> 2); 115: outputbuffer[2] = ((databuffer[2] & 0x03) << 6) databuffer[3]; 116: 117: // add all non-padded bytes in output buffer to decoded data 118: for (var k:uint = 0; k < outputbuffer.length; k ) { 119: if (databuffer[k 1] == 64) break; 120: output.writebyte(outputbuffer[k]); 121: } 122: } 123: 124: // rewind decoded data bytearray 125: output.position = 0; 126: 127: // return decoded data 128: return output; 129: } 130: 131: public function base64() { 132: throw new error("base64 class is static container only"); 133: } 134: } 135: }
php代码:
1: 2: 3: $today = date("ymd_his"); 4: $filename = $today."_img.png"; 5: $somecontent = base64_decode($_request['png']); 6: 7: if ($handle = fopen("upload/".$filename, "w ")) { 8: if (!fwrite($handle, $somecontent) == false) { 9: fclose($handle); 10: } 11: 12: echo "imageurl=".$filename; 13: } 14: 15: ?>
本文参考:
swf to png with actionscript 3.0 - bytearray class
利用flex 实现截图功能
转载于:https://www.cnblogs.com/meteoric_cry/archive/2011/04/06/2006884.html
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的flex php截图demo的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇:
- 下一篇: