更新 'SrcJuMethod.js'

Ju
src48597962 2 years ago
parent 1ef46e5193
commit eed6614799
  1. 73
      SrcJuMethod.js

@ -89,76 +89,3 @@ function banner(start, arr, data, cfg){
putMyVar('banneri', i); putMyVar('banneri', i);
}, obj)) }, obj))
} }
//图片压缩
function imageCompress(imgurl,fileid) {
function compress(path,inSampleSize,topath) {
if (!path) {
return false;
}
let tmpfile = "hiker://files/_cache/1.txt";
if (!fileExist(tmpfile)) {
writeFile(tmpfile, '');
}
const Bitmap = android.graphics.Bitmap;
const BitmapFactory = android.graphics.BitmapFactory;
const FileOutputStream = java.io.FileOutputStream;
let options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize||2;
options.inPurgeable = true;
let bitmap;
if (topath && typeof path === "object" && path.getClass) {
bitmap = BitmapFactory.decodeStream(path, null, options);
closeMe(path);
} else {
bitmap = BitmapFactory.decodeFile(path, options);
topath = topath || path;
}
let os = new FileOutputStream(topath);
let s = false;
try {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
s = true;
} catch (e) {
log(e.toString());
}
os.flush();
os.close();
return s;
}
function getPicInfo(path){
const BitmapFactory = android.graphics.BitmapFactory;
let options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inPurgeable = true;
if (!path) {
return {
outWidth: 0,
outHeight: 0
};
}
let bitmap;
if (typeof path === "object" && path.getClass) {
bitmap = BitmapFactory.decodeStream(path, null, options);
closeMe(path);
} else {
bitmap = BitmapFactory.decodeFile(path, options);
}
//options.inJustDecodeBounds = false;
return options;
//getPicInfo(f).outWidth
//getPicInfo(f).outHeight
}
function getName(path) {
const File = java.io.File;
return new File(path).getName() + "";
}
let f = fetch(imgurl, {
inputStream: true
});
let ff = f;
let newpath = "/storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/"+(fileid||"")+"_"+getName(imgurl);
log(getPicInfo(f));
compress(ff,3,newpath);
return "file://"+newpath;
}

Loading…
Cancel
Save