Commit 9b0d4771 by sikang

Simugu Bug修复 第二版

parent e72b4a25
......@@ -68,7 +68,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
}
} catch (Throwable e) {
onError(Error.APP_ERROR, "Program Exception: " + msg);
onError(Error.APP_ERROR, "Error: " + msg);
}
if (disposable != null)
disposable.dispose();
......
......@@ -82,7 +82,7 @@ public class TakePhotoActivity extends BaseActivity {
cameraView = findViewById(R.id.cameraView);
maskImv = findViewById(R.id.activity_takephoto_mask_imv);
cameraView.setTargetPreviewSize(1920, 1080);
cameraView.setTargetPreviewSize(1280, 720);
int mask = getIntent().getIntExtra("preview_mask", 0);
int btnImg = getIntent().getIntExtra("shoot_btn_img", 0);
......@@ -106,7 +106,16 @@ public class TakePhotoActivity extends BaseActivity {
if (!image.exists()) {
image.mkdir();
}
BitmapUtils.saveBitmapToSDCard(bitmap, image, 100);
File file = BitmapUtils.saveBitmapToSDCard(bitmap, image, 100);
//如果图片过大,则压缩
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.putExtra("image_path", image.getAbsolutePath());
setResult(RESULT_OK, intent);
......
......@@ -267,4 +267,5 @@ public class BitmapUtils {
return bitmapDrawable.getBitmap();
}
}
......@@ -17,6 +17,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import tech.starwin.utils.ui_utils.DialogFactory;
/**
* Created by SiKang on 2018/12/14.
*/
......@@ -27,11 +29,13 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
//默认预览尺寸
private int imageWidth = 1920;
private int imageHeight = 1080;
//帧率
private int frameRate = 30;
//默认View尺寸
private int defaultWidth = 0;
private int defaultHeight = 0;
private boolean isCaptureImage = false;
private OnSurfaceChangedListener surfaceChangedListener;
public CameraView(Context context) {
......@@ -64,9 +68,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
//设置Camera基本参数
if (mCamera != null)
initCameraParams();
}
@Override
......@@ -126,9 +128,15 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
defaultWidth = MeasureSpec.getSize(widthMeasureSpec);
defaultHeight = MeasureSpec.getSize(heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
/**
* 摄像头配置
......@@ -145,16 +153,19 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
break;
}
}
camParams.setPreviewSize(imageWidth, imageHeight);
camParams.setPictureSize(imageWidth, imageHeight);
// camParams.setPreviewSize(imageWidth, imageHeight);
// camParams.setPictureSize(imageWidth, imageHeight);
// Log.v(TAG, "Setting imageWidth: " + imageWidth + " imageHeight: " + imageHeight + " frameRate: " + frameRate);
camParams.setPreviewFrameRate(frameRate);
// Log.v(TAG, "Preview Framerate: " + camParams.getPreviewFrameRate());
mCamera.setParameters(camParams);
// mCamera.setParameters(camParams);
//取到的图像默认是横向的,这里旋转90度,保持和预览画面相同
mCamera.setDisplayOrientation(90);
if (defaultWidth != 0) {
float xy = ((float) imageWidth) / imageHeight;
int heightSize = (int) (xy * defaultWidth);
layout(0, (defaultHeight - heightSize) / 2, defaultWidth, heightSize + (defaultHeight - heightSize) / 2);
startPreview();
}
}
......@@ -195,6 +206,9 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
try {
mCamera = Camera.open(cameraId);
if (mCamera != null) {
initCameraParams();
}
} catch (Exception e) {
if (mCamera != null) {
mCamera.release();
......
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/qmui_config_color_gray_9"
tools:ignore="NewApi">
<item android:drawable="@color/white" />
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/qmui_config_color_gray_9"
tools:ignore="NewApi">
<item android:drawable="@color/white" />
</ripple>
\ No newline at end of file
<selector></selector>
\ No newline at end of file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/white">
<tech.starwin.widget.CameraView
android:id="@+id/cameraView"
......
......@@ -20,7 +20,7 @@
android:textColor="@color/qmui_config_color_gray_3" />
<TextView
android:layout_width="match_parent"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
......
......@@ -8,7 +8,7 @@
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/shape_rectangle_navy_solid"
android:orientation="vertical">
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
......
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