Commit db00830c by sikang

add luban

parent 14d11c5c
...@@ -131,6 +131,9 @@ dependencies { ...@@ -131,6 +131,9 @@ dependencies {
api 'com.squareup.retrofit2:converter-gson:2.4.0' api 'com.squareup.retrofit2:converter-gson:2.4.0'
api 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' api 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
api 'top.zibin:Luban:1.1.8'
// firebase core // firebase core
// api 'com.google.firebase:firebase-core:16.0.3' // api 'com.google.firebase:firebase-core:16.0.3'
// firebase cloud message // firebase cloud message
......
...@@ -29,6 +29,8 @@ import tech.starwin.utils.context_utils.ActivityJumper; ...@@ -29,6 +29,8 @@ import tech.starwin.utils.context_utils.ActivityJumper;
import tech.starwin.utils.context_utils.EasyActivityResult; import tech.starwin.utils.context_utils.EasyActivityResult;
import tech.starwin.utils.ui_utils.QMUIHelper; import tech.starwin.utils.ui_utils.QMUIHelper;
import tech.starwin.utils.ui_utils.UIHelper; import tech.starwin.utils.ui_utils.UIHelper;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;
import com.common.widget.CameraView; import com.common.widget.CameraView;
import com.common.widget.TopBar; import com.common.widget.TopBar;
...@@ -142,17 +144,39 @@ public class TakePhotoActivity extends BaseActivity { ...@@ -142,17 +144,39 @@ public class TakePhotoActivity extends BaseActivity {
return; return;
} }
//如果图片过大,则压缩 //如果图片过大,则压缩
long size = FileUtils.getFileSize(file) / 1024; // long size = FileUtils.getFileSize(file) / 1024;
if (FileUtils.getFileSize(file) / 1024 > 1024) { // if (FileUtils.getFileSize(file) / 1024 > 1024) {
int quality = (int) (100 * (1024f / size)); // int quality = (int) (100 * (1024f / size));
file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality); // file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality);
//
// }
Intent intent = new Intent();
Luban.with(TakePhotoActivity.this)
.load(file)
.ignoreBy(100)
.setFocusAlpha(false)
.setTargetDir(file.getParent())
.setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
} }
Intent intent = new Intent(); @Override
public void onSuccess(File file) {
intent.putExtra("image_path", file.getAbsolutePath()); intent.putExtra("image_path", file.getAbsolutePath());
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();
}
@Override
public void onError(Throwable e) {
setResult(RESULT_CANCELED);
finish();
}
}).launch();
}); });
} else if (v.getId() == R.id.button_cancel) { } else if (v.getId() == R.id.button_cancel) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment