Commit 13d4f873 by sikang

bug fix

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