Commit 13d4f873 by sikang

bug fix

parent b3bc1139
...@@ -8,32 +8,24 @@ import android.view.View; ...@@ -8,32 +8,24 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import com.common.base.BaseActivity;
import com.common.toolbox.tracker.TrackEvent; import com.common.toolbox.tracker.TrackEvent;
import com.common.widget.CameraView;
import com.common.widget.TopBar;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import tech.starwin.R; import tech.starwin.R;
import com.common.base.BaseActivity;
import tech.starwin.impl.OnNoShakeClickListener; import tech.starwin.impl.OnNoShakeClickListener;
import tech.starwin.utils.BitmapUtils; import tech.starwin.utils.BitmapUtils;
import tech.starwin.utils.FileUtils; import tech.starwin.utils.FileUtils;
import tech.starwin.utils.PreferencesManager;
import tech.starwin.utils.SPDataProvider;
import tech.starwin.utils.TrackEventHelper; import tech.starwin.utils.TrackEventHelper;
import tech.starwin.utils.context_utils.ActivityJumper; 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.Luban;
import top.zibin.luban.OnCompressListener;
import com.common.widget.CameraView;
import com.common.widget.TopBar;
/** /**
* Created by SiKang on 2018/9/25. * Created by SiKang on 2018/9/25.
...@@ -112,7 +104,7 @@ public class TakePhotoActivity extends BaseActivity { ...@@ -112,7 +104,7 @@ public class TakePhotoActivity extends BaseActivity {
} else if (TextUtils.equals(type, PhotoType.WORK_CARD.name())) { } else if (TextUtils.equals(type, PhotoType.WORK_CARD.name())) {
TrackEventHelper.logEvent(TrackEvent.Click.WORK_CARD_SHOT); TrackEventHelper.logEvent(TrackEvent.Click.WORK_CARD_SHOT);
photoType = PhotoType.WORK_CARD; photoType = PhotoType.WORK_CARD;
}else{ } else {
photoType = PhotoType.OTHERS_IMG; photoType = PhotoType.OTHERS_IMG;
} }
...@@ -121,62 +113,27 @@ public class TakePhotoActivity extends BaseActivity { ...@@ -121,62 +113,27 @@ public class TakePhotoActivity extends BaseActivity {
public void onEventClick(View v) { public void onEventClick(View v) {
if (v.getId() == R.id.button_shoot) { if (v.getId() == R.id.button_shoot) {
cameraView.captureImage(bitmap -> { cameraView.captureImage(bitmap -> {
// long pix_size = bitmap.getWidth() * bitmap.getHeight(); try {
// float scale = 720 * 1080 / (float) pix_size;
// BitmapUtils.scaleBitmap(bitmap, scale);
// if(TextUtils.equals(type, PhotoType.KTP.name())){
// SPDataProvider.saveKTPImage(bitmap);
// }else if(TextUtils.equals(type, PhotoType.WORK_CARD.name())){
// SPDataProvider.saveWorkImage(bitmap);
// }
// setResult(RESULT_OK);
// finish();
File image = FileUtils.getImageFile(getApplicationContext(), photoType.img_path); File image = FileUtils.getImageFile(getApplicationContext(), photoType.img_path);
if (!image.exists()) { if (!image.exists()) {
image.mkdir(); image.mkdir();
} }
File file = BitmapUtils.saveBitmapToSDCard(bitmap, image, 100); File file = BitmapUtils.saveBitmapToSDCard(bitmap, image, 100);
if (file == null) { if (file != null) {
setResult(RESULT_CANCELED); //压缩
finish(); file = Luban.with(TakePhotoActivity.this).load(file).get().get(0);
return;
}
//如果图片过大,则压缩
// long size = FileUtils.getFileSize(file) / 1024;
// if (FileUtils.getFileSize(file) / 1024 > 1024) {
// int quality = (int) (100 * (1024f / size));
// file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality);
//
// }
Intent intent = new Intent(); Intent intent = new Intent();
Luban.with(TakePhotoActivity.this)
.load(file)
.ignoreBy(100)
.setFocusAlpha(false)
.setTargetDir(file.getParent())
.setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
}
@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 } catch (Exception e) {
public void onError(Throwable e) {
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
} }
}).launch();
}); });
} else if (v.getId() == R.id.button_cancel) { } else if (v.getId() == R.id.button_cancel) {
......
...@@ -11,7 +11,6 @@ import android.util.AttributeSet; ...@@ -11,7 +11,6 @@ import android.util.AttributeSet;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -106,19 +105,14 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C ...@@ -106,19 +105,14 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
public void onPreviewFrame(byte[] data, Camera camera) { public void onPreviewFrame(byte[] data, Camera camera) {
if (previewPictureCallback != null && isCaptureImage) { if (previewPictureCallback != null && isCaptureImage) {
isCaptureImage = false; isCaptureImage = false;
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
Camera.Size size = camera.getParameters().getPreviewSize(); Camera.Size size = camera.getParameters().getPreviewSize();
final YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null); final YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, size.width, size.height), 100, stream); image.compressToJpeg(new Rect(0, 0, size.width, size.height), 100, stream);
Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size()); Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
if (bmp != null) {
previewPictureCallback.onImage(bmp); previewPictureCallback.onImage(bmp);
}
}
}).start(); }).start();
} }
} }
......
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