fix: 修改连拍间隔1秒时出现白屏照片的问题,增加全局线程池处理jpg转webp
This commit is contained in:
parent
04c2ecf8e3
commit
91ebf6e291
@ -87,6 +87,8 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE;
|
||||
import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER;
|
||||
@ -306,42 +308,12 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
||||
}
|
||||
File file = new File(finalVideoPath);
|
||||
initMarkerPaper();
|
||||
Runnable runnable = new Runnable() {
|
||||
result.toFile(file, new FileCallback() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.toFile(file, new FileCallback() {
|
||||
@Override
|
||||
public void onFileReady(@Nullable File file) {
|
||||
if (file!=null&&file.exists()){
|
||||
WebPNative webPNative = new WebPNative();
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||
webPNative.encodeRGBA(bitmap, file.getPath(), 90);
|
||||
runOnUiThread(new Runnable() {
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void run() {
|
||||
if (file.exists()) {
|
||||
initMarker();
|
||||
videoIndex = Integer.parseInt(file.getName().replace(".webp", ""));
|
||||
finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp";
|
||||
tvTitle.setText("保存成功:" + (videoIndex + 1));
|
||||
}
|
||||
if (radioPicture == 1) {
|
||||
Message message = new Message();
|
||||
message.what = 0x103;
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!bitmap.isRecycled()) {
|
||||
bitmap.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
public void onFileReady(@Nullable File file) {
|
||||
UserApplication.fixedThreadPool.execute(new Jpg2WebpRunnable(result, file));
|
||||
}
|
||||
};
|
||||
UserApplication.fixedThreadPool.submit(runnable);
|
||||
});
|
||||
} else {
|
||||
isBack = false;
|
||||
if (isOration) {
|
||||
@ -362,6 +334,59 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
|
||||
tvMapView.setLayoutParams(layoutParamsMap);
|
||||
}
|
||||
|
||||
class Jpg2WebpRunnable implements Runnable {
|
||||
private PictureResult pictureResult;
|
||||
private File file;
|
||||
|
||||
public Jpg2WebpRunnable(PictureResult pictureResult,File file) {
|
||||
this.pictureResult = pictureResult;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (file.exists() && file != null) {
|
||||
WebPNative webPNative = new WebPNative();
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||
webPNative.encodeRGBA(bitmap, file.getPath(), 90);
|
||||
if (!bitmap.isRecycled()) {
|
||||
bitmap.recycle();
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (file.exists()) {
|
||||
initMarker();
|
||||
videoIndex = Integer.parseInt(file.getName().replace(".webp", ""));
|
||||
finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp";
|
||||
tvTitle.setText("保存成功:" + (videoIndex + 1));
|
||||
}
|
||||
if (radioPicture == 1) {
|
||||
Message message = new Message();
|
||||
message.what = 0x103;
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
isBack = false;
|
||||
if (isOration) {
|
||||
stopTimer();
|
||||
}
|
||||
if (radioPicture != 1) {
|
||||
capturePicture.setText("开始采集");
|
||||
}
|
||||
capturePicture.setChecked(false);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(PicturesActivity.this, "源文件不存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initLine() {
|
||||
if (geoWkt != null) {
|
||||
String geo = Geohash.getInstance().decode(geoWkt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user