更新 'SrcJuMethod.js'

Ju
src48597962 2 years ago
parent ad87fa5b56
commit d0145cb499
  1. 37
      SrcJuMethod.js

@ -91,6 +91,7 @@ function banner(start, arr, data, cfg){
}
//图片压缩
function imageCompress(imgurl,fileid) {
/*
function compress(path, inSampleSize, topath) {
const Bitmap = android.graphics.Bitmap;
const BitmapFactory = android.graphics.BitmapFactory;
@ -170,4 +171,40 @@ function imageCompress(imgurl,fileid) {
log(r);
return "file://" + newpath;
}
*/
function compress(path, inSampleSize, topath) {
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 (!path) {
return false;
}
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;
}
let f = fetch(imgurl, {
inputStream: true
});
compress(f, 8, "/storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/1.jpg");
return "file:///storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/1.jpg"
}

Loading…
Cancel
Save