|
|
@@ -57,6 +57,10 @@ import java.lang.reflect.Type;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.camera.core.CameraSelector;
|
|
|
@@ -403,7 +407,7 @@ public class MainActivity extends BaseActivity {
|
|
|
Log.e("-------->","------>savePath="+outputFileResults.getSavedUri().getPath());
|
|
|
Log.e("-------->","------>保存成功");
|
|
|
// Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
|
|
|
-// savePicture(file, path, name);
|
|
|
+ savePicture(file, path, name);
|
|
|
mWebView.loadUrl("javascript:uploadPhotoPath('" + outputFileOptions.getFile().getAbsolutePath() + "')");
|
|
|
}
|
|
|
|
|
|
@@ -415,8 +419,21 @@ public class MainActivity extends BaseActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ boolean isStart = false;
|
|
|
+ ExecutorService fixedThreadPool;
|
|
|
private void savePicture(File file, String path, String name) {
|
|
|
- ApiHelper.uploadPicture(this, file, path, name);
|
|
|
+ if (!isStart){
|
|
|
+ isStart = true;
|
|
|
+ int numberOfCores = Runtime.getRuntime().availableProcessors();
|
|
|
+ Log.i("--------->", "-------->cpu核心数" + numberOfCores);
|
|
|
+ fixedThreadPool = Executors.newFixedThreadPool(2*numberOfCores+1);
|
|
|
+ }
|
|
|
+ fixedThreadPool.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ApiHelper.uploadPicture(MainActivity.this, file, path, name);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void checkNet() {
|
|
|
@@ -601,6 +618,8 @@ public class MainActivity extends BaseActivity {
|
|
|
// 设置拍照模式为最小化延迟模式,这意味着拍照时将尽可能快地捕获图像。
|
|
|
imageCapture = new ImageCapture.Builder()
|
|
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
|
+ // 设置JPEG的质量为85%
|
|
|
+ .setJpegQuality(85)
|
|
|
.build();
|
|
|
cameraProvider.unbindAll();//解绑组件
|
|
|
cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector, preview, imageCapture);
|
|
|
@@ -974,5 +993,8 @@ public class MainActivity extends BaseActivity {
|
|
|
if (cameraProvider!=null){
|
|
|
cameraProvider.unbindAll();
|
|
|
}
|
|
|
+ if (fixedThreadPool!=null){
|
|
|
+ fixedThreadPool.shutdown();
|
|
|
+ }
|
|
|
}
|
|
|
}
|