From d0145cb499bfb6042ede135332fee485ba1dc886 Mon Sep 17 00:00:00 2001 From: src48597962 <48597962@qq.com> Date: Fri, 4 Aug 2023 15:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'SrcJuMethod.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SrcJuMethod.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/SrcJuMethod.js b/SrcJuMethod.js index 9e32994a..040f0e64 100644 --- a/SrcJuMethod.js +++ b/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" }