Created
December 22, 2017 05:32
-
-
Save bigxixi/4e2662b0efb296be369358344b19651c to your computer and use it in GitHub Desktop.
AE脚本-图片转Binary编码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//本脚本用于将图片转为binary编码 | |
if(!app.preferences.getPrefAsLong("Main Pref Section", "Pref_SCRIPTING_FILE_NETWORK_SECURITY")){ | |
alert("请勾选 ‘首选项’->'常规'->'允许脚本写入文件和访问网络'。"); | |
app.executeCommand(2359); | |
}else{ | |
alert("选择要转换的文件,完成后会弹出对话框显示代码,另有一份存储在图片文件位置,文件名为图片名+.txt","图片转Binary编码 by Bigxixi"); | |
var myImageFileURI = File("~/Desktop/").openDlg("选择要转换的文件"); | |
var myFile = new File(myImageFileURI); | |
myFile.encoding="BINARY"; | |
myFile.open(); | |
var myBin = myFile.read().toSource().replace("(new String(", "").replace(/\)\)$/, "") +';'; | |
var saveB = new File(myImageFileURI.fsName+'.txt'); | |
saveB.open("w"); | |
saveB.encoding = "UTF-8"; | |
saveB.write(myBin); | |
saveB.close(); | |
var thePal = new Window("dialog",myImageFileURI.name,undefined); | |
thePal.bounds = {x:100,y:100,width:600,height:400}; | |
var thePath = thePal.add('statictext'); | |
thePath.bounds = {x:0,y:5,width:600,height:30}; | |
thePath.text = 'Binary File Path: ' + decodeURIComponent(myImageFileURI.fsName); | |
var theView = thePal.add("edittext",undefined,'binary',{readonly:1,noecho:0,borderless:1,multiline:1,enterKeySignalsOnChange:0}); | |
theView.bounds = {x:0,y:35,width:600,height:320}; | |
theView.text = myBin; | |
btn11 = thePal.add("button",undefined,'Close'); | |
btn11.bounds = {x:250,y:365,width:100,height:30}; | |
btn11.onClick = function(){ | |
thePal.close(); | |
} | |
thePal.center(); | |
thePal.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment