作者:lostfire98
引用:FFish Script base64 函数
引用:base64类
版权:SWFKit Pro 3.4
效果打包EXE,不含源文件,感兴趣的朋友请利用以下源码
复制内容到剪贴板
代码:
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//功能注:转换BitmapData成JPG,用SWFKit打包后不需要服务器和其它外部控件支持既可直接在本地生成图片
//汇源者:大盗二十八
//拓展注:读取,混淆,生成,还原任意二进制文件,其它您能想到的,前提是自己清楚加密算法哈
//用法注:第一步,Flash cs3,建立一个包含图片的mc,然后删除,再在库中设置该mc的链接名为"mc",拖个Button组件到库中,在场景第一帧加上as;
//用法注:第二步,SWFKit Pro3.4(3.2版本也可),导入swf后,在Scripts窗口右上方Items处下拉条选择Initialize,然后粘贴属于FFish的函数代码。
///////////////////////////////////////////////////////////////////////////////////////////////////////////
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
import mx.graphics.codec.JPEGEncoder;
import Base64;
import SWFKit.*;
var P_Btn1: Button;
var P_Btn2: Button;
var P_line: Sprite;
var P_Box : Sprite;
var P_Pic = new mc();
function Paint_it() {
P_Btn1 = new Button();
P_Btn1.y = 350;
P_Btn1.x = 5;
P_Btn1.label = "清除";
P_Btn2 = new Button();
P_Btn2.y = 390;
P_Btn2.x = 5;
P_Btn2.label = "保存";
addChild(P_Btn1);
addChild(P_Btn2);
P_Btn1.addEventListener(MouseEvent.MOUSE_DOWN, P_Clear);
P_Btn2.addEventListener(MouseEvent.MOUSE_DOWN, P_Save);
addEventListener(MouseEvent.MOUSE_DOWN, P_Down);
addEventListener(MouseEvent.MOUSE_UP, P_Up);
P_Box = new Sprite();
P_line = new Sprite();
P_line.graphics.lineStyle(5,0xffcc00);
addChild(P_Box);
P_Box.addChild(P_Pic);
P_Pic.addChild(P_line);
P_Pic.x = 110;
P_Pic.y = 5;
}
function P_Clear(event:MouseEvent):void {
event.stopPropagation();//看帮助吧,很详尽,呵呵。
P_line.graphics.clear();
P_line.graphics.lineStyle(5,0xffcc00);
}
function P_Save(event:MouseEvent):void {
event.stopPropagation();
var P_Bmp:BitmapData = new BitmapData(P_Pic.width, P_Pic.height);
P_Bmp.draw(P_Pic);
var P_Jpg:JPEGEncoder = new JPEGEncoder(75);
var P_Byte:ByteArray = P_Jpg.encode(P_Bmp);
var encoded:String = Base64.encodeByteArray(P_Byte);
ExternalInterface.call("saveByte", encoded);//直接调用SWFKit的FFish Script语言Initialize标签saveByte函数,传递字符串。
//[color=Red]这个是两软件交换数据之处![/color]
}
function P_Down(event:MouseEvent):void {
addEventListener(MouseEvent.MOUSE_MOVE, P_Move);
P_line.graphics.moveTo(mouseX-110, mouseY);
}
function P_Move(event:MouseEvent):void {
P_line.graphics.lineTo(mouseX-110, mouseY);
}
function P_Up(event:MouseEvent):void {
removeEventListener(MouseEvent.MOUSE_MOVE, P_Move);
}
Paint_it();
///////////////////////////////////////////////////////////
//以下代码请写到SWFKit的Scripts里Items的Initialize内:
////////////////////////////////////////////////////////////
//Initialize
//getAdditionalFile();
//return true;
function saveByte(file) {
var converter = new Base64();
var newStream = converter.decode(file);
var dlg = new Dialogs;
var output = dlg.fileSave("JPG Files(*.jpg)|*.jpg|All Files(*.*)|*.*|", "jpg","bitmap_jpg.jpg");
newStream.saveToFile(output);
}
function Base64()
{
this.keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function readByte(input)
{
var ch = input.get();
if (input.eof) return NaN;
return ch;
}
function encode(input)
{
var output = new StringStream;
var chr1, chr2, chr3 ;
var enc1, enc2, enc3, enc4;
do
{
chr1 = this.readByte(input);
chr2 = this.readByte(input);
chr3 = this.readByte(input);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2))
{
enc3 = enc4 = 64;
}
else if (isNaN(chr3))
{
enc4 = 64;
}
output.write(this.keyStr.charAt(enc1) + this.keyStr.charAt(enc2) +
this.keyStr.charAt(enc3) + this.keyStr.charAt(enc4));
} while (!input.eof);
return output;
}
function decode(input)
{
var output = new StringStream;
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
var base64test = new RegExp("[^A-Za-z0-9+/=]", "g");
if (base64test.exec(input))
{
trace("Base64.decode: ", "invalid input string");
return null;
}
do
{
enc1 = this.keyStr.indexOf(input.charAt(i++));
enc2 = this.keyStr.indexOf(input.charAt(i++));
enc3 = this.keyStr.indexOf(input.charAt(i++));
enc4 = this.keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output.put(String.fromCharCode(chr1));
if (enc3 != 64)
{
output.put(String.fromCharCode(chr2));
}
if (enc4 != 64)
{
output.put(String.fromCharCode(chr3));
}
} while (i < input.length);
return output;
}
}