Skip to content

Commit ec0e89b

Browse files
author
Sumn
committed
增加相册拍照功能
1 parent b4676b7 commit ec0e89b

7 files changed

Lines changed: 769 additions & 1 deletion

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.seeyou.toolkit.utils;
2+
3+
import android.content.Context;
4+
import android.hardware.camera2.CameraAccessException;
5+
import android.hardware.camera2.CameraManager;
6+
7+
/**
8+
* @author xialei
9+
* date 2019/8/2
10+
*/
11+
public class CameraUtils {
12+
13+
14+
/**
15+
* 检查设备是否有摄像头
16+
*
17+
* @return
18+
*/
19+
public static boolean hasCamera() {
20+
CameraManager manager = (CameraManager) Utils.getApp().getSystemService(Context.CAMERA_SERVICE);
21+
String[] cameraIds;
22+
try {
23+
cameraIds = manager.getCameraIdList();
24+
if (cameraIds.length > 0) {
25+
//后置摄像头存在
26+
if (cameraIds[0] != null) {
27+
return true;
28+
}
29+
30+
if (cameraIds[1] != null) {
31+
return true;
32+
}
33+
} else {
34+
return false;
35+
}
36+
} catch (CameraAccessException e) {
37+
e.printStackTrace();
38+
return false;
39+
}
40+
return false;
41+
}
42+
43+
44+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.seeyou.toolkit.utils;
2+
3+
import android.graphics.Bitmap;
4+
5+
6+
public class Crop {
7+
8+
private int aspectX = 1;
9+
private int aspectY = 1;
10+
private boolean crop = true;
11+
private boolean circleCrop = false;
12+
private String outputFormat = Bitmap.CompressFormat.JPEG.toString();
13+
private boolean scale = true;
14+
private boolean scaleUpIfNeeded = true;
15+
private int outputX = 360;
16+
private int outputY = 360;
17+
18+
public Crop() {
19+
}
20+
21+
public int aspectX() {
22+
return aspectX;
23+
}
24+
25+
public Crop aspectX(int aspectX) {
26+
this.aspectX = aspectX;
27+
return this;
28+
}
29+
30+
public int aspectY() {
31+
return aspectY;
32+
}
33+
34+
public Crop aspectY(int aspectY) {
35+
this.aspectY = aspectY;
36+
return this;
37+
}
38+
39+
public boolean crop() {
40+
return crop;
41+
}
42+
43+
public Crop crop(boolean crop) {
44+
this.crop = crop;
45+
return this;
46+
}
47+
48+
public boolean circleCrop() {
49+
return circleCrop;
50+
}
51+
52+
public Crop circleCrop(boolean circleCrop) {
53+
this.circleCrop = circleCrop;
54+
return this;
55+
}
56+
57+
public String outputFormat() {
58+
return outputFormat;
59+
}
60+
61+
public Crop outputFormat(String outputFormat) {
62+
this.outputFormat = outputFormat;
63+
return this;
64+
}
65+
66+
public boolean scale() {
67+
return scale;
68+
}
69+
70+
public Crop scale(boolean scale) {
71+
this.scale = scale;
72+
return this;
73+
}
74+
75+
public boolean scaleUpIfNeeded() {
76+
return scaleUpIfNeeded;
77+
}
78+
79+
public Crop scaleUpIfNeeded(boolean scaleUpIfNeeded) {
80+
this.scaleUpIfNeeded = scaleUpIfNeeded;
81+
return this;
82+
}
83+
84+
public int outputX() {
85+
return outputX;
86+
}
87+
88+
public Crop outputX(int outputX) {
89+
this.outputX = outputX;
90+
return this;
91+
}
92+
93+
public int outputY() {
94+
return outputY;
95+
}
96+
97+
public Crop outputY(int outputY) {
98+
this.outputY = outputY;
99+
return this;
100+
}
101+
}

0 commit comments

Comments
 (0)