Camera2API的基本功能笔记 Android实现Camera2预览和拍照效果
简介
网上对于 Camera2 的介绍有很多,在 Github 上也有很多关于 Camera2 的封装库,但是对于那些库,封装性太强,有时候我们仅仅是需要个简简单单的拍照功能而已,因此,自定义一个 Camera 使之变得轻量级那是非常重要的了。(本文并非重复造轮子, 而是在于学习 Camera2API 的基本功能, 笔记之。)
学习要点:
(资料图片)
使用 Android Camera2 API 的基本功能。
迭代连接到设备的所有相机的特征。
显示相机预览和拍摄照片。
Camera2 API 为连接到 Android 设备的各个相机设备提供了一个界面。 它替代了已弃用的 Camera 类。
使用 getCameraIdList 获取所有可用摄像机的列表。 然后,您可以使用 getCameraCharacteristics,并找到适合您需要的最佳相机(前 / 后面,分辨率等)。
创建一个 CameraDevice.StateCallback 的实例并打开相机。 当相机打开时,准备开始相机预览。
使用 TextureView 显示相机预览。 创建一个 CameraCaptureSession 并设置一个重复的 CaptureRequest。
静像拍摄需要几个步骤。 首先,需要通过更新相机预览的 CaptureRequest 来锁定相机的焦点。
然后,以类似的方式,需要运行一个预捕获序列。之后,它准备拍摄一张照片。 创建一个新的 CaptureRequest 并调用 [capture] 。
完成后,别忘了解锁焦点。
实现效果环境
SDK>21
Camera2 类图
代码实现
CameraPreview.java
/**
* Created by shenhua on 2017-10-20-0020.
* Email shenhuanet@126.com
*/
public class CameraPreview extends TextureView {
private static final String TAG = "CameraPreview";
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();//从屏幕旋转转换为JPEG方向
private static final int MAX_PREVIEW_WIDTH = 1920;//Camera2 API 保证的最大预览宽高
private static final int MAX_PREVIEW_HEIGHT = 1080;
private static final int STATE_PREVIEW = 0;//显示相机预览
private static final int STATE_WAITING_LOCK = 1;//焦点锁定中
private static final int STATE_WAITING_PRE_CAPTURE = 2;//拍照中
private static final int STATE_WAITING_NON_PRE_CAPTURE = 3;//其它状态
private static final int STATE_PICTURE_TAKEN = 4;//拍照完毕
private int mState = STATE_PREVIEW;
private int mRatioWidth = 0, mRatioHeight = 0;
private int mSensorOrientation;
private boolean mFlashSupported;
private Semaphore mCameraOpenCloseLock = new Semaphore(1);//使用信号量 Semaphore 进行多线程任务调度
private Activity activity;
private File mFile;
private HandlerThread mBackgroundThread;
private Handler mBackgroundHandler;
private Size mPreviewSize;
private String mCameraId;
private CameraDevice mCameraDevice;
private CaptureRequest.Builder mPreviewRequestBuilder;
private CaptureRequest mPreviewRequest;
private CameraCaptureSession mCaptureSession;
private ImageReader mImageReader;
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
ORIENTATIONS.append(Surface.ROTATION_90, 0);
ORIENTATIONS.append(Surface.ROTATION_180, 270);
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
public CameraPreview(Context context) {
this(context, null);
}
public CameraPreview(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CameraPreview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mFile = new File(getContext().getExternalFilesDir(null), "pic.jpg");
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (0 == mRatioWidth || 0 == mRatioHeight) {
setMeasuredDimension(width, height);
} else {
if (width < height * mRatioWidth / mRatioHeight) {
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
} else {
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
}
}
public void onResume(Activity activity) {
this.activity = activity;
startBackgroundThread();
//当Activity或Fragment OnResume()时,可以冲洗打开一个相机并开始预览,否则,这个Surface已经准备就绪
if (this.isAvailable()) {
openCamera(this.getWidth(), this.getHeight());
} else {
this.setSurfaceTextureListener(mSurfaceTextureListener);
}
}
public void onPause() {
closeCamera();
stopBackgroundThread();
}
public void setOutPutDir(File file) {
this.mFile = file;
}
public void setAspectRatio(int width, int height) {
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Size can"t be negative");
}
mRatioWidth = width;
mRatioHeight = height;
requestLayout();
}
public void setAutoFlash(CaptureRequest.Builder requestBuilder) {
if (mFlashSupported) {
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
}
}
public void takePicture() {
lockFocus();
}
private void startBackgroundThread() {
mBackgroundThread = new HandlerThread("CameraBackground");
mBackgroundThread.start();
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}
private void stopBackgroundThread() {
mBackgroundThread.quitSafely();
try {
mBackgroundThread.join();
mBackgroundThread = null;
mBackgroundHandler = null;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
* 处理生命周期内的回调事件
*/
private final TextureView.SurfaceTextureListener mSurfaceTextureListener = new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
openCamera(width, height);
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
configureTransform(width, height);
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture texture) {
}
};
/**
* 相机状态改变回调
*/
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice cameraDevice) {
mCameraOpenCloseLock.release();
Log.d(TAG, "相机已打开");
mCameraDevice = cameraDevice;
createCameraPreviewSession();
}
@Override
public void onDisconnected(@NonNull CameraDevice cameraDevice) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
@Override
public void onError(@NonNull CameraDevice cameraDevice, int error) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
if (null != activity) {
activity.finish();
}
}
};
/**
* 处理与照片捕获相关的事件
*/
private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result) {
switch (mState) {
case STATE_PREVIEW: {
break;
}
case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (afState == null) {
captureStillPicture();
} else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
mState = STATE_PICTURE_TAKEN;
captureStillPicture();
} else {
runPreCaptureSequence();
}
}
break;
}
case STATE_WAITING_PRE_CAPTURE: {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_NON_PRE_CAPTURE;
}
break;
}
case STATE_WAITING_NON_PRE_CAPTURE: {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
mState = STATE_PICTURE_TAKEN;
captureStillPicture();
}
break;
}
}
}
@Override
public void onCaptureProgressed(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull CaptureResult partialResult) {
process(partialResult);
}
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
process(result);
}
};
/**
* 在确定相机预览大小后应调用此方法
*
* @param viewWidth 宽
* @param viewHeight 高
*/
private void configureTransform(int viewWidth, int viewHeight) {
if (null == mPreviewSize || null == activity) {
return;
}
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
this.setTransform(matrix);
}
/**
* 根据mCameraId打开相机
*/
private void openCamera(int width, int height) {
setUpCameraOutputs(width, height);
configureTransform(width, height);
CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
try {
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Time out waiting to lock camera opening.");
}
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
}
}
/**
* 关闭相机
*/
private void closeCamera() {
try {
mCameraOpenCloseLock.acquire();
if (null != mCaptureSession) {
mCaptureSession.close();
mCaptureSession = null;
}
if (null != mCameraDevice) {
mCameraDevice.close();
mCameraDevice = null;
}
if (null != mImageReader) {
mImageReader.close();
mImageReader = null;
}
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
} finally {
mCameraOpenCloseLock.release();
}
}
/**
* 设置相机相关的属性或变量
*
* @param width 相机预览的可用尺寸的宽度
* @param height 相机预览的可用尺寸的高度
*/
@SuppressWarnings("SuspiciousNameCombination")
private void setUpCameraOutputs(int width, int height) {
CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
// 在这个例子中不使用前置摄像头
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
continue;
}
Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
ImageFormat.JPEG, /*maxImages*/2);
mImageReader.setOnImageAvailableListener(
mOnImageAvailableListener, mBackgroundHandler);
int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
// noinspection ConstantConditions
mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
boolean swappedDimensions = false;
switch (displayRotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
if (mSensorOrientation == 90 || mSensorOrientation == 270) {
swappedDimensions = true;
}
break;
case Surface.ROTATION_90:
case Surface.ROTATION_270:
if (mSensorOrientation == 0 || mSensorOrientation == 180) {
swappedDimensions = true;
}
break;
default:
Log.e(TAG, "Display rotation is invalid: " + displayRotation);
}
Point displaySize = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
int rotatedPreviewWidth = width;
int rotatedPreviewHeight = height;
int maxPreviewWidth = displaySize.x;
int maxPreviewHeight = displaySize.y;
if (swappedDimensions) {
rotatedPreviewWidth = height;
rotatedPreviewHeight = width;
maxPreviewWidth = displaySize.y;
maxPreviewHeight = displaySize.x;
}
if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
maxPreviewWidth = MAX_PREVIEW_WIDTH;
}
if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
maxPreviewHeight = MAX_PREVIEW_HEIGHT;
}
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
maxPreviewHeight, largest);
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
} else {
setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
}
Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
mFlashSupported = available == null ? false : available;
mCameraId = cameraId;
return;
}
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (NullPointerException e) {
Log.e(TAG, "设备不支持Camera2");
}
}
/**
* 获取一个合适的相机预览尺寸
*
* @param choices 支持的预览尺寸列表
* @param textureViewWidth 相对宽度
* @param textureViewHeight 相对高度
* @param maxWidth 可以选择的最大宽度
* @param maxHeight 可以选择的最大高度
* @param aspectRatio 宽高比
* @return 最佳预览尺寸
*/
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight,
int maxWidth, int maxHeight, Size aspectRatio) {
List bigEnough = new ArrayList<>();
List notBigEnough = new ArrayList<>();
int w = aspectRatio.getWidth();
int h = aspectRatio.getHeight();
for (Size option : choices) {
if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
option.getHeight() == option.getWidth() * h / w) {
if (option.getWidth() >= textureViewWidth &&
option.getHeight() >= textureViewHeight) {
bigEnough.add(option);
} else {
notBigEnough.add(option);
}
}
}
if (bigEnough.size() > 0) {
return Collections.min(bigEnough, new CompareSizesByArea());
} else if (notBigEnough.size() > 0) {
return Collections.max(notBigEnough, new CompareSizesByArea());
} else {
Log.e(TAG, "Couldn"t find any suitable preview size");
return choices[0];
}
}
/**
* 为相机预览创建新的CameraCaptureSession
*/
private void createCameraPreviewSession() {
try {
SurfaceTexture texture = this.getSurfaceTexture();
assert texture != null;
// 将默认缓冲区的大小配置为想要的相机预览的大小
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
Surface surface = new Surface(texture);
mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
// 我们创建一个 CameraCaptureSession 来进行相机预览
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
if (null == mCameraDevice) {
return;
}
// 会话准备好后,我们开始显示预览
mCaptureSession = cameraCaptureSession;
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(mPreviewRequestBuilder);
mPreviewRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
/**
* 从指定的屏幕旋转中检索照片方向
*
* @param rotation 屏幕方向
* @return 照片方向(0,90,270,360)
*/
private int getOrientation(int rotation) {
return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}
/**
* 锁定焦点
*/
private void lockFocus() {
try {
// 如何通知相机锁定焦点
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
// 通知mCaptureCallback等待锁定
mState = STATE_WAITING_LOCK;
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
/**
* 解锁焦点
*/
private void unlockFocus() {
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
setAutoFlash(mPreviewRequestBuilder);
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
mState = STATE_PREVIEW;
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
/**
* 拍摄静态图片
*/
private void captureStillPicture() {
try {
if (null == activity || null == mCameraDevice) {
return;
}
final CaptureRequest.Builder captureBuilder =
mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mImageReader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(captureBuilder);
// 方向
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));
CameraCaptureSession.CaptureCallback captureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
Toast.makeText(getContext(), "Saved: " + mFile, Toast.LENGTH_SHORT).show();
Log.d(TAG, mFile.toString());
unlockFocus();
}
};
mCaptureSession.stopRepeating();
mCaptureSession.abortCaptures();
mCaptureSession.capture(captureBuilder.build(), captureCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
/**
* 运行preCapture序列来捕获静止图像
*/
private void runPreCaptureSequence() {
try {
// 设置拍照参数请求
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
mState = STATE_WAITING_PRE_CAPTURE;
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
/**
* 比较两者大小
*/
private static class CompareSizesByArea implements Comparator {
@Override
public int compare(Size lhs, Size rhs) {
return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
(long) rhs.getWidth() * rhs.getHeight());
}
}
/**
* ImageReader的回调对象
*/
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));
}
};
/**
* 将捕获到的图像保存到指定的文件中
*/
private static class ImageSaver implements Runnable {
private final Image mImage;
private final File mFile;
ImageSaver(Image image, File file) {
mImage = image;
mFile = file;
}
@Override
public void run() {
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
FileOutputStream output = null;
try {
output = new FileOutputStream(mFile);
output.write(bytes);
} catch (IOException e) {
e.printStackTrace();
} finally {
mImage.close();
if (null != output) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
CameraPreview cameraView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraView = (CameraPreview) findViewById(R.id.cameraView);
}
@Override
protected void onResume() {
super.onResume();
cameraView.onResume(this);
}
@Override
protected void onPause() {
cameraView.onPause();
super.onPause();
}
public void takePic(View view) {
cameraView.takePicture();
}
}
activity_main.xml
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="com.shenhua.ocr.activity.Main2Activity">
android:id="@+id/cameraView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:background="@drawable/ic_capture_200px"
android:onClick="takePic"
android:text="TAKE"
app:layout_constraintBottom_toBottomOf="@id/constraintLayout"
app:layout_constraintEnd_toEndOf="@id/constraintLayout"
app:layout_constraintStart_toStartOf="@id/constraintLayout"
app:layout_constraintTop_toTopOf="@id/cameraView"
app:layout_constraintVertical_bias="0.97" />
资源文件 ic_capture_200px.xml
android:viewportWidth="1024.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
其它
Manifest 权限:
Android6.0 运行时权限未贴出。(注意:为了方便读者手机端阅读,本文代码部分的成员变量使用了行尾注释,在正常编程习惯中,请使用 /* / 注释。)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
标签:
相关推荐:
最新新闻:
- C、C++和C#有什么区别?三个小故事带你快速了解C、C++和C#的区别 全球快资讯
- 9-10个月的宝宝喜欢看什么样的图?详情介绍|世界报道
- 每日聚焦:解析M3U8索引文件 下载M3U8视频文件的解析
- 最新手机壳价格怎样?最新手机壳报价大全
- 视讯!ios8越狱后必装插件有哪些?ios8越狱后必装插件汇总
- 【技术】Unity3d的布局 SceneView
- 视频会议系统是什么意思?有哪些功能?-当前速看
- vr场景怎么做?VR视频制作教程|每日信息
- 微信塞班版为什么退出后会自动启动?问题出在哪里?
- Android 代码中文字在手机上显示乱码怎么办?解决方法_环球今亮点
- Camera2API的基本功能笔记 Android实现Camera2预览和拍照效果
- abb变频电机怎么样?abb变频电机价格是多少?
- 英语字母表你会背吗?26个英语字母表及字母音标
- 【干货】互联网广告基本术语、计费方式及流程-全球即时看
- 联想笔记本一键恢复7.0怎么用?详细方法步骤-天天快看点
- Word文档中如何输入汉字的偏旁部首?输入汉字的偏旁部首方法
- 一次汇报的内容有多页 如何用母版做美化?
- 世界速看:什么叫信息化管理?信息化管理相关介绍
- 苹果颠覆MP3 手机业的“创新”是怎么做到的?|环球报道
- 地磁场的基本形态与演化 你知道多少?
- bose家庭影院好吗?bose家庭影院有哪些优势?
- 世界速读:金松冰箱怎么样?金松冰箱多少钱?详细介绍
- 如何实现国产化替代?博思得凭借新一代OX平台技术做到了_世界速讯
- PS分配内存不足怎么办?解决方案来了
- 如何搭建个人网站?创建网站的第一步是什么?
- 焦点要闻:camel_Apache Camel日志组件示例
- 全球热门:电商数据分析中的基础分析项目——京东订单数据预处理
- 天天微头条丨摩托罗拉xt532怎么刷机?摩托罗拉xt532刷机教程介绍
- 焦点速讯:高效空气过滤器有什么作用?高效空气过滤器作用介绍
- 人工生命中最关键的一步——虚拟细胞的构建|全球今日报
- GE带以太网接口的CPU协议有哪些特性?详情介绍
- nokia5300怎么刷机?nokia5300刷机教程及手机优势
- 百度闪付如何添加银行卡?百度闪付添加银行卡方法
- 环球观热点:反间计你知道吗?史上最经典的10大反间计
- getParameter和getAttribute的区别是什么?区别介绍 全球最资讯
- 如何在Win10登陆界面添加签名?Win10登陆界面添加签名方法
- 中国电池企业前十名有哪些?中国电池企业前十名介绍
- 中国互联网10大平台 2010年中国互联网十大开放平台大盘点
- 怎么打开优酷的kux格式?kux转换成mp4的方法 快看
- 常用的数学函数 数据分析最常用的excel函数公式大全 世界快看
- 德国曼瑞德温控器怎么样?德国曼瑞德温控器介绍
- d3dx9_34.dll是什么?系统d3dx9_34.dll错误会带来什么危害?|每日播报
- 华为nova5手机无法开机怎么办?华为nova5手机维修
- 什么是实数?数轴上的点与实数是什么意思?
- 下载软件哪个好?迅雷、迅雷和比特彗星下载工具介绍 全球微动态
- 科幻小说作家赫内·巴赫札维勒:时间旅行的悖论-全球滚动
- 什么是pdi检测?Pentaho数据集成的步骤
- 速递!FTP中文件名乱码问题怎么解决?Serv-U8字符编码的设置
- 如何使用任务计划程序来定时启动?黑客干货教程!-焦点消息
- JAVA模拟器安装方法 JAVA模拟器全功略!
- 54岁休·杰克曼老当益壮:下海冬泳不带怕!
- 林志颖术后首复出:恢复良好 面部无任何疤痕-天天滚动
- 观速讯丨超“小行星”撞地球今日中午上演 法英荷均肉眼可见
- 《全职猎人》全新舞台剧艺图拍摄花絮 5月12日开演:今热点
- 泡饭寿司没人吃,大米为何在日韩失宠? 焦点热议
- 医保卡少了几十元,为啥年轻人焦虑了? 天天快资讯
- 全球微动态丨至强散热,比纸还薄!一加Ace 2 x 瑞声科技量身定制超薄超大VC
- 卢伟冰出手了!512G 版 Redmi K60 降至 3000 元以内_世界新动态
- 摄像头绝了!索尼Xperia 1 V渲染图曝光 观察
- 全球要闻:ChatGPT爆火:谷歌开始检查Bard AI代码数据
- 环球即时:小米 13 Lite 手机渲染图曝光:采用灵动岛设计
- 《CSGO》G2夺冠IEM卡托维兹 尼公子四进决赛终圆梦|全球速看
- 女子多设备同时登腾讯视频账号被封 解锁需超级会员_报资讯
- 世嘉新作《404 GAME RE:SET》公开新人物介绍 2023年春上线
- 开发商十分忙碌 《控制2》已进入概念验证阶段-热门看点
- 环球热讯:封杀《霍格沃茨之遗》的论坛运营者狂玩本作:太香了
- 【环球播资讯】情人节送巧克力,是不是没诚意?
- 聚焦:融资丨「派迅智能」完成数亿元B轮融资,赛富投资基金领投
- 年轻人选择“包地创业”,这门生意究竟有没有前景?
- 环球新资讯:“吃得多,还是瘦?”妻子一句话,丈夫查出大问题
- 赚钱新招儿!苹果的iPhone硬件订阅可能会在三月份到来_当前热议
- iPhone 15都没这功能!工程师通过添加USB-C制造双端口iPhone-环球快看点
- “灵动岛”双前摄设计!小米13 Lite曝光:天天关注
- 入职1小时被HR告知招错人补偿50元 当事人:很无奈
- 《生化危机4:重制版》豪华版带14款DLC 有专属藏宝图内容:环球微动态