我拍摄的照片是低分辨率,如何使其完全解决?

时间:2017-11-03 22:57:50

标签: android camera

我正在尝试为项目构建简单的相机应用但我不能使用相机相机库,如相机套件。而且我没有使用Camera2 apis,因为我需要向后兼容性。

我有自定义CameraPreview(扩展SurfaceView实现SurfaceHolder.Callback)类App显示实时预览。但是当我将图像保存在我的主要活动中时,它会以320x240的分辨率保存。

我无法理解为什么它在240p中保存以及如何以全分辨率保存这些数据?

这是它保存图片的活动;

public class FullscreenActivity extends Activity implements Camera.PictureCallback {
    public final static String DEBUG_TAG = "MakePhotoActivity";
    public Camera camera;
    private int cameraId = 0;

    private Uri filerui;
    boolean visibility =false;
    private static final String IMAGE_DIRECTORY_NAME = "hellocamera";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        //Check Permission
        FullscreenActivityPermissionsDispatcher.NeedCameraPermissinWithPermissionCheck(this);

        // do we have a camera?
        cameraId = findCamera();
        if (getBoolean()) {
            visibility=true;
            camera=Camera.open(cameraId);
            initCameraPreview();
        }
    }

    //iniitaiate preview
    public void initCameraPreview(){
        CameraPreview cameraPreview= (CameraPreview) findViewById(R.id.camerePreview);
        if (visibility) {
            cameraPreview.setVisibility(View.VISIBLE);
            visibility=false;
        }
        cameraPreview.init(camera);
    }

    //This is the button ı capture photos
    public void onClick(View view) {
        camera.takePicture(null, null, this );
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File imagesFolder = new File(Environment.getExternalStorageDirectory(), "DCIM");
        imagesFolder.getAbsolutePath();
        String fileName = Helper.save();
        File output = new File(imagesFolder, fileName);

        Uri uriSavedImage = Uri.fromFile(output);
        imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

        OutputStream imageFileOS;
        try {
            imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
            imageFileOS.write(data);
            imageFileOS.flush();
            imageFileOS.close();

        } catch (FileNotFoundException e) {
            //  Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // Auto-generated catch block
            e.printStackTrace();
        }
    }

1 个答案:

答案 0 :(得分:0)

好的,我自己解决了这个问题,结果发现我无法正确实现parameters.getSupportedPictureSizes())。如果其他人遇到类似问题,这也可能是您问题的根源。