图片base加解码(输入图片路径解码图片)

"ui";
ui.layout(
<frame background="http://img02.sogoucdn.com/app/a/100520146/2c74d5c6cadbbc80f0753ccaddd55e5a">
<vertical>
<img id="img" w="117" bg="#00000000" margin="114 0 0 120" />
</vertical>
<vertical>
<input id="ym" text="/storage/emulated/0/DCIM/Screenshots/Screenshot_2018-01-14-04-02-22-84.png" bg="#00000000" gravity="left" margin="104 0 0 8" h="138" w="342"/>
<input id="jg" bg="#00000000" gravity="left" margin="50 0 0 8" h="138" w="342"/>
</vertical> <vertical><linear >
<button w="81" id="bm" margin="238 0 0 5" h="32" bg="#00000000" textSize="20sp"/>
<button w="81" id="jm" margin="238 0 0 1" h="32" bg="#00000000" textSize="20sp"/>
<vertical>
<text id="hx" text="" textStyle="bold" gravity="center" size="16" margin="238 0 0 1" bg="#00000000" w="20" color="#000000"/>
<text id="hx2" text="√" textStyle="bold" gravity="center" size="16" margin="5 0 0 1" bg="#00000000" w="20" color="#000000"/>
</vertical>
</linear>
<button w="81" id="qq" margin="170 0 0 0" h="" w="" bg="#00000000" textSize="20sp"/>
</vertical></frame>
);
f1=0;
f2=0;
threads.start(function(){
while(true){
ui.run(function(){
if(files.isFile(ui.ym.text())){
f1=ui.ym.text();
}else{f1=0;f2=0;}
if(f1!=0){if(f1!=f2){
var bmp=android.graphics.BitmapFactory.decodeFile(f1);
ui.img.setImageBitmap(bmp);
f2=f1;
}}else{ui.img.setSource("file://null");}
});
sleep(100);
}
});
ui.bm.click(() => {
if(f1==0){
ui.jg.text(c(android.util.Base64.encode(a(ui.ym.text()),0)));
}else{
var oin = null;
oin = new java.io.FileInputStream(f1);
var lt=oin.available();
var data=a(new Array(lt+1)+"");
lt=oin.read(data);
ui.jg.text("data:image/png;base64,"+c(android.util.Base64.encode(data,0)).replace("\n", ""));
}
});
ui.jm.click(() => {
mm=ui.jg.text();
mma=mm.split("data:image/png;base64,");
if(mma.length==2){
try{
var data=android.util.Base64.decode(a(mma[1]),0);
var path0="/sdcard/base64图片/";
var path=path0+"bs64"+bytestohexstring(md5(data,"md5"))+".png";
files.createWithDirs(path0);
files.writeBytes(path,data);
ui.img.setSource("file://"+path);
ui.ym.text(path);}catch(e){ui.ym.text("解码失败");}
}else{
ui.ym.text(c(android.util.Base64.decode(a(mm),0)));}
});
ui.hx.click(() => {
alert("暂未开放此功能");
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?card_type=group&uin=332093831",
packageName: "com.tencent.mobileqq",
});
});
ui.qq.click(() => {
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?card_type=group&uin=332093831",
packageName: "com.tencent.mobileqq",
});
});
function a(b) {
return c(b).getBytes();
}
function c(a) {
return java.lang.String(a);
}
function md5(str,lx){
var md5 = java.security.MessageDigest.getInstance(lx);
md5.update(java.lang.String(str).getBytes());
return md5.digest();
}
function bytestohexstring(bytes) {
var val = ""; 
for (var i = 0; i < bytes.length; i++) {  
var tmp = bytes[i];
if (tmp < 0) {
tmp = 256 + tmp;
}
tmp= tmp.toString(16);
if((tmp+"").length==1){
tmp="0"+tmp;
}
val+=tmp;
}
return val;
}

最后由 BW6a4sp1kWN 编辑

有出错呦
Wrapped java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: length=0; index=-1 (ui.js#6)
at script(ui.js:6)
at script(<bas64>:2)

  • 3
    帖子
  • 687
    浏览

与 Auto.js 的连接断开,我们正在尝试重连,请耐心等待