更新 'SrcJuMethod.js'

Ju
src48597962 2 years ago
parent 44a776ea49
commit 2a44fa6e79
  1. 50
      SrcJuMethod.js

@ -93,9 +93,8 @@ function banner(start, arr, data, cfg){
function imageCompress(imgurl,fileid) { function imageCompress(imgurl,fileid) {
function compress(path, topath) { function compress(path, topath) {
if (!path) { if (!path) {
return imgurl; return false;
} }
let obj = Object.assign({},path);
let tmpfile = "hiker://files/_cache/1.txt"; let tmpfile = "hiker://files/_cache/1.txt";
if (!fileExist(tmpfile)) { if (!fileExist(tmpfile)) {
writeFile(tmpfile, ''); writeFile(tmpfile, '');
@ -103,47 +102,29 @@ function imageCompress(imgurl,fileid) {
const Bitmap = android.graphics.Bitmap; const Bitmap = android.graphics.Bitmap;
const BitmapFactory = android.graphics.BitmapFactory; const BitmapFactory = android.graphics.BitmapFactory;
const FileOutputStream = java.io.FileOutputStream; const FileOutputStream = java.io.FileOutputStream;
let options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inPurgeable = true;
let bitmap;
let options1 = new BitmapFactory.Options(); if (topath && typeof path === "object" && path.getClass) {
options1.inJustDecodeBounds = true; bitmap = BitmapFactory.decodeStream(path, null, options);
options1.inPurgeable = true; closeMe(path);
let bitmap1;
if (typeof path === "object" && path.getClass) {
bitmap1 = BitmapFactory.decodeStream(path, null, options1);
} else { } else {
bitmap1 = BitmapFactory.decodeFile(path, options1); bitmap = BitmapFactory.decodeFile(path, options);
} topath = topath || path;
options1.inJustDecodeBounds = false;
let size;
if(options1.outWidth>=options1.outHeight){
size = options1.outWidth;
}else{
size = options1.outHeight;
}
if(size>720){
let options2 = new BitmapFactory.Options();
options2.inSampleSize = parseInt(size/720) || 2;
options2.inPurgeable = true;
let bitmap2;
if (topath && typeof obj === "object" && obj.getClass) {
bitmap2 = BitmapFactory.decodeStream(obj, null, options2);
closeMe(obj);
} else {
bitmap2 = BitmapFactory.decodeFile(obj, options2);
topath = topath || obj;
} }
let os = new FileOutputStream(topath); let os = new FileOutputStream(topath);
let s = false;
try { try {
bitmap2.compress(Bitmap.CompressFormat.PNG, 100, os); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
return "file://" + topath; s = true;
} catch (e) { } catch (e) {
log(e.toString()); log(e.toString());
} }
os.flush(); os.flush();
os.close(); os.close();
} return s;
return imgurl;
} }
function getName(path) { function getName(path) {
const File = java.io.File; const File = java.io.File;
@ -153,5 +134,6 @@ function imageCompress(imgurl,fileid) {
inputStream: true inputStream: true
}); });
let newpath = "/storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/"+(fileid||"")+"_"+getName(imgurl); let newpath = "/storage/emulated/0/Android/data/com.example.hikerview/files/Documents/_cache/"+(fileid||"")+"_"+getName(imgurl);
return compress(f, newpath); compress(f, newpath);
return "file://"+newpath;
} }

Loading…
Cancel
Save