我最近正在使用Camera 2 API,我的设备的屏幕比例为16:9,但是我的相机传感器为4:3。因此,我得到的所有预览尺寸均为4:3。我想知道有什么办法可以使作物大小并仅显示16:9的部分吗?我尝试了很长时间,但没有发现对相机2的任何帮助。
我当前的相机代码类似于相机2基本示例。
那么,如何裁剪预览并仅在纹理视图上显示16:9部分?
谢谢!!
在我的相机应用程序中,我有一个按钮可以将相机面向前方或后方更改,我可以使用后置相机捕捉和保存图像,但是当我切换到前置相机时,我无法捕捉图像.这就是我将相机切换到前面或后面的方式.
ImageView switch_camera =(ImageView) rootview.findViewById(R.id.imageView7);
switch_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
//isfrontcam=true;
try {
//manager.openCamera(getBackFacingCameraId(manager), mStateCallback, mBackgroundHandler);
closeCamera();
openCamera(mTextureView.getWidth(), mTextureView.getHeight(),"0");
Log.e("opening ","BackCam");
facing = 1;
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} else if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
// isfrontcam = true;
try {
//manager.openCamera(getFrontFacingCameraId(manager), mStateCallback, mBackgroundHandler);
// characteristics = manager.getCameraCharacteristics("1");
closeCamera();
openCamera(mTextureView.getWidth(), …Run Code Online (Sandbox Code Playgroud) 基本上,我想要做的是通过应用程序中的按钮单击更改CONTROL_AE_MODE.用户可以使用AUTO闪光(ON_AUTO_FLASH),如果ON(ON_ALWAYS_FLASH)或OFF(CONTROL_AE_MODE_OFF)则使用.
在此示例中:https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
第818行,他们设置闪光灯一次:
// Use the same AE and AF modes as the preview.
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(captureBuilder);
// Orientation
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
showToast("Saved: " + mFile);
Log.d(TAG, mFile.toString());
unlockFocus();
}
};
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
Run Code Online (Sandbox Code Playgroud)
然后在840行构建CaptureSession.
有没有办法在预览后更改CONTROL_AE_MODE?
我试过改造会议,这有点奏效:
if(flashMode == CameraView.CAMERA_FLASH_ON){
Log.e("CAMERA 2", "FLASH ON");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
}else if(flashMode == CameraView.CAMERA_FLASH_OFF){
Log.e("CAMERA 2", "FLASH OFF"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用camera2API(底部的代码)来获取/计算设备相机的FOV 。
在尝试使用Galaxy S7时:
SENSOR_INFO_PHYSICAL_SIZE)。CameraCharacteristics似乎是错误的。在三星Galaxy A3-2016上进行的相同查询和实验更具说服力,计算出的HFOV似乎与实验值相符。
有没有人可以分享有关CameraCharacteristics读数可靠性的经验或数据?
我用来查询CameraCharacteristics:: 的代码
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraID);
if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT)
continue;
int support = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY )
Log.d("mr", "Camera " + cameraID + " has LEGACY Camera2 support");
else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED )
Log.d("mr", "Camera " + cameraID + " has LIMITED Camera2 support");
else if( …Run Code Online (Sandbox Code Playgroud) 我正在基于Camera2Basic示例制作自定义相机应用,并对其进行了修改以使用手动设置。
将CONTROL_AWB_MODE设置CONTROL_AWB_MODE_AUTO为时,预览很好。但如下图所示,在三星s6 / s7中将设置为并设置为后CONTROL_MODE,它变为绿色。CONTROL_AWB_MODECONTROL_AWB_MODE_OFFCONTROL_AWB_LOCKtrue
我正在使用Camera2API构建相机活动,将拍摄的图像发送到另一个活动.在某些设备上它可以工作,但在其他设备(较慢的设备)上,我得到一个java.lang.IllegalStateException,其中显示"会话已关闭;进一步的更改是非法的".
我在这一行得到了这个异常(在updatePreview()中):
cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);
Run Code Online (Sandbox Code Playgroud)
这是我的完整代码:
public class NewCamera extends CustomActivity implements TimingActivity {
private static final String TAG = "NewCamera";
private ImageView takePictureButton;
private TextureView textureView;
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
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);
}
private String cameraId;
protected CameraDevice cameraDevice;
protected CameraCaptureSession cameraCaptureSessions;
protected CaptureRequest.Builder captureRequestBuilder;
private Semaphore mCameraOpenCloseLock = new Semaphore(1);
private Size imageDimension;
private ImageReader imageReader;
private static final int REQUEST_CAMERA_PERMISSION = 200;
private …Run Code Online (Sandbox Code Playgroud) I saw the following in the Android documentation for camera2 from API level 23:
https://developer.android.com/reference/android/graphics/ImageFormat.html#DEPTH16
https://developer.android.com/reference/android/graphics/ImageFormat.html#DEPTH_POINT_CLOUD
However I could not find any practical examples of those. Are there any Android devices that support this API ?
Many thanks,
Guillaume
我正在Android设备上实现相机应用程序。当前,我使用Camera2 API和ImageReader来获取YUV_420_888格式的图像数据,但是我不知道如何将这些数据准确地写入MediaCodec。
这是我的问题:
YUV_420_888啊该格式YUV_420_888是不明确的,因为它可以属于任何形式YUV420的家庭,如YUV420P,YUV420PP,YUV420SP和YUV420PSP,对不对?
通过访问图像的三个平面(#0,#1,#2),我可以获得该图像的Y(#0),U(#1),V(#2)值。但是这些值的排列在不同设备上可能不相同。例如,如果YUV_420_888确实表示YUV420P,则Plane#1和Plane#2的大小均为Plane#0的四分之一。如果YUV_420_888确实表示YUV420SP,则Plane#1和Plane#2的大小都是Plane#0大小的一半(Plane#1和Plane#2的每个包含U,V值)。
如果要将这些数据从图像的三个平面写入MediaCodec,我需要转换为哪种格式?YUV420,NV21,NV12 ...
COLOR_FormatYUV420Flexible啊该格式COLOR_FormatYUV420Flexible也有歧义,因为它可以是属于该YUV420家族的任何格式,对吗?如果将KEY_COLOR_FORMATMediaCodec对象的选项设置为COLOR_FormatYUV420Flexible,我应该输入哪种格式的数据(YUV420P,YUV420SP ...?)?
COLOR_FormatSurface?我知道MediaCodec具有自己的表面,如果我将KEY_COLOR_FORMATMediaCodec对象的选项设置为,则可以使用该表面COLOR_FormatSurface。使用Camera2 API,我不需要自己将任何数据写入MediaCodec对象。我可以耗尽输出缓冲区。
但是,我需要从相机更改图像。例如,绘制其他图片,在上面写一些文字,或将另一个视频插入为POP(图片的图片)。
我可以使用ImageReader从Camera读取图像,然后重新绘制图像,然后将新数据写入MediaCodec的表面,然后将其排干吗?怎么做?
编辑1
我通过使用COLOR_FormatSurface和RenderScript 实现了该功能。这是我的代码:
onImageAvailable 方法:
public void onImageAvailable(ImageReader imageReader) {
try {
try (Image image = imageReader.acquireLatestImage()) {
if (image == null) …Run Code Online (Sandbox Code Playgroud) 在我们的应用程序更新后,我们现在使用Camera2 API,遗憾的是预览在我们的测试设备上拉伸:Samsung SM-J330F/DS,Android-Version 8.0.0,API 26
因为我们在同一设备上没有遇到Googles Camera2Basic项目的这个问题,所以我们尝试调整我们的项目以使用相同的预览实现.目前我们无法弄清楚两个项目之间不同预览的确切原因.
这是预期的:
与Camera2Basic项目相比,我们RelativeLayout在Activity类中以编程方式创建,AutoFitTextureView然后将其添加到此对象:
mMainLayout = new FrameLayout(this);
mMainLayout.setBackgroundColor(Color.BLACK);
mMainLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
mPreview = new AutoFitTextureView(this);
mPreview.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, Gravity.TOP));
mMainLayout.addView(mPreview);
this.setContentView(mMainLayout);
Run Code Online (Sandbox Code Playgroud)
实现AutoFitTextureView与Camera2Basic项目相同.
稍后在将预览设置setUpCameraOutputs()为640x480像素(所有设备应支持的分辨率)之后的Camera2类中,我们调用setAspectRatio(width, height)mPreview:
mPreviewSize = new Size(640, 480);
if (mFrameOrientation == Configuration.ORIENTATION_LANDSCAPE) {
mTextureView.setAspectRatio(
mPreviewSize.getWidth(), mPreviewSize.getHeight()
);
} else {
mTextureView.setAspectRatio(
mPreviewSize.getHeight(), mPreviewSize.getWidth()
);
}
Run Code Online (Sandbox Code Playgroud)
注意:同样在较新的设备上(如荣誉10),预览看起来很好.
android-camera2 ×10
android ×9
java ×3
camera ×2
depth ×1
mobile ×1
point-clouds ×1
preview ×1
textureview ×1
yuv ×1