Android 相机 - 是否可以限制图像大小?

问题描述 投票:0回答:1

我正在 Android 手机上开发这个应用程序,
在较新的手机上,捕获的图像有时为 10MB -> 8000 x 6000 像素。
这对于我们的应用程序和使用来说是一种过度的杀伤力。我们需要较小的图像尺寸

这是捕获图像的代码,
是否可以将相机限制在特定尺寸?
假设最大图像尺寸为 4032 x 3024
或者
是否可以将相机的最大图像尺寸限制为 3MB
谢谢!

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                                                  "com.example.android.fileprovider",
                                                  photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}
java android android-camera
1个回答
0
投票

设置 EXTRA_SIZE_LIMIT。这是最大大小(以字节为单位)。现在相机应用程序可能会忽略此标志(这是一个请求,而不是强制值),但它应该适用于大多数相机应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.