gpt4 book ai didi

android - 为什么不能改变图像的分辨率?

转载 作者:行者123 更新时间:2023-12-04 23:58:31 25 4
gpt4 key购买 nike

这是我的代码启动相机并使用Camerax:

ImageCapture imageCapture;
ImageAnalysis imageAnalysis;
private void startCamera() {

final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this);

cameraProviderFuture.addListener(new Runnable() {
@Override
public void run() {
try {
// Camera provider is now guaranteed to be available
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();

// Set up the view finder use case to display camera preview
Preview preview = new Preview.Builder().build();

int DefaultPictureSizeWidth=1280;
int DefaultPictureSizeHeight=720;

imageAnalysis = new ImageAnalysis.Builder()
.setTargetResolution(new Size(DefaultPictureSizeWidth,DefaultPictureSizeHeight))
.build();


imageAnalysis.setAnalyzer(Executors.newFixedThreadPool(1), new ImageAnalysis.Analyzer() {
@Override
public void analyze(@NonNull ImageProxy image) {
image.close();
}
}
);

// Set up the capture use case to allow users to take photos
ImageCapture.Builder imageCaptureBulder = new ImageCapture.Builder();
imageCaptureBulder.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY);
imageCapture=imageCaptureBulder.build();
// Choose the camera by requiring a lens facing

CameraSelector.Builder bulder = new CameraSelector.Builder();
bulder.requireLensFacing(CameraSelector.LENS_FACING_BACK);
CameraSelector cameraSelector= bulder.build();

// Attach use cases to the camera with the same lifecycle owner
try{
cameraProvider.unbindAll();
mCamera = cameraProvider.bindToLifecycle((LifecycleOwner)MainActivity.this,cameraSelector,imageCapture,preview,imageAnalysis);

preview.setSurfaceProvider(
mPreviewView.getSurfaceProvider());
} catch (Exception e) {
// Log.d(TAG, "Use case binding failed")
}



} catch (InterruptedException | ExecutionException e) {
// Currently no exceptions thrown. cameraProviderFuture.get()
// shouldn't block since the listener is being called, so no need to
// handle InterruptedException.
}
}
}, ContextCompat.getMainExecutor(this));
}

我将 setTargetResolution 设置为 Size(1280,720)

但结果图像的分辨率仍然是最大(4032x3024)

如何改变图片的分辨率?

最佳答案

根据docs :

CameraX will apply the best suitable resolution based on the requests.If the primary need is to satisfy aspect ratio, specify onlysetTargetAspectRatio, and CameraX will determine a specific resolutionsuitable based on the device. If the primary need of the app is tospecify a resolution in order to make image processing more efficient(for example a small or mid-sized image based on device processingcapability), use setTargetResolution(Size resolution).

你可以试试

imageAnalysis = new ImageAnalysis.Builder()
.setTargetResolution(new Size(DefaultPictureSizeWidth,DefaultPictureSizeHeight))
.build();
.setTargetAspectRatio(Rational(3,4)) //Tweak this as desired

但是,通常看来目标分辨率取决于设备。

关于android - 为什么不能改变图像的分辨率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72199921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com