Skip to content

Commit 4839114

Browse files
committed
更新文档和添加保存图片按钮
1 parent 59e11f4 commit 4839114

5 files changed

Lines changed: 29 additions & 5 deletions

File tree

notes/00_Android系统相机拍照的常见问题及解决方案.md

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Android系统相机拍照适配问题和方案
2+
3+
## 基本的实现思路
4+
5+
## 改进后的实现思路
6+
7+
## 兼容Android 6.0的实现思路

src/main/java/com/clock/study/activity/PhotoPreviewActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Bitmap;
66
import android.support.v7.app.AppCompatActivity;
77
import android.os.Bundle;
8+
import android.util.Log;
89
import android.widget.ImageView;
910

1011
import com.clock.study.R;
@@ -33,13 +34,17 @@ protected void onCreate(Bundle savedInstanceState) {
3334
super.onCreate(savedInstanceState);
3435
setContentView(R.layout.activity_photo_preview);
3536

36-
mPhotoPreview = (ImageView) findViewById(R.id.iv_photo_preview);
37+
mPhotoPreview = (ImageView) findViewById(R.id.iv_preview_photo);
3738

3839
mImageFile = (File) getIntent().getSerializableExtra(EXTRA_IMAGE);
3940
int requestWidth = (int) (RuleUtils.getScreenWidth(this) * RATIO);
4041
int requestHeight = (int) (RuleUtils.getScreenHeight(this) * RATIO);
4142
Bitmap bitmap = BitmapUtils.decodeBitmapFromFile(mImageFile, requestWidth, requestHeight);//按照屏幕宽高的3/4比例进行缩放显示
4243
if (bitmap != null) {
44+
int degree = BitmapUtils.getBitmapDegree(mImageFile.getAbsolutePath());//检查是否有被旋转,并进行纠正
45+
if (degree != 0) {
46+
bitmap = BitmapUtils.rotateBitmapByDegree(bitmap, degree);
47+
}
4348
mPhotoPreview.setImageBitmap(bitmap);
4449
}
4550
}
@@ -49,4 +54,5 @@ public static void preview(Activity activity, File file) {
4954
previewIntent.putExtra(EXTRA_IMAGE, file);
5055
activity.startActivity(previewIntent);
5156
}
57+
5258
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5+
android:orientation="vertical"
56
android:paddingBottom="@dimen/activity_vertical_margin"
67
android:paddingLeft="@dimen/activity_horizontal_margin"
78
android:paddingRight="@dimen/activity_horizontal_margin"
89
android:paddingTop="@dimen/activity_vertical_margin">
910

11+
<Button
12+
android:id="@+id/btn_save_photo"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="@string/save_photo" />
16+
1017
<ImageView
11-
android:id="@+id/iv_photo_preview"
18+
android:id="@+id/iv_preview_photo"
1219
android:layout_width="match_parent"
13-
android:layout_height="match_parent" />
14-
</RelativeLayout>
20+
android:layout_height="match_parent"
21+
android:layout_marginTop="5dp" />
22+
23+
24+
</LinearLayout>

src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<string name="start_camera_error">启动相机失败</string>
44
<string name="photo_preview">PhotoPreview</string>
55
<string name="take_photo">TakePhoto</string>
6+
<string name="save_photo">保存图片</string>
67
</resources>

0 commit comments

Comments
 (0)