如何捕捉从相机中的照片,而不意图而不、意图、相机、照片

2023-09-06 04:16:38 作者:金钱始终是最大的诱惑丶

我想我的应用程序,以便能够拍摄照片,而无需使用其他应用程序。在code,我用:

I want my app to be able to capture photos without using another application. The code i used :

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = null;
    try
    {
        photo = this.createTemporaryFile("picture", ".jpg");
        photo.delete();
    }
    catch(Exception e)
    {
        Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();

    }
    mImageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

但是,这code使用手机的主摄像头应用程序。任何人都可以给我一些code?

But this code uses the phone's main camera app. Can anyone give me some code ?

推荐答案

拍摄照片直接使用摄像机类是出奇的复杂,得到正确的。

Taking a picture directly using the Camera class is insanely complicated to get right.

我的工作库来简化这个,在这里你只需要添加一个 CameraFragment 您的应用程序的基本preVIEW UI,和呼叫 takePicture()它来拍照,各种方式来配置的行为(例如,其中照片得到保存)。然而,这个库仍处于进展中的工作。

I am working on a library to simplify this, where you just add a CameraFragment to your app for the basic preview UI, and call takePicture() on it to take a picture, with various ways to configure the behavior (e.g., where the pictures get saved). However, this library is still a work in progress.

任何人都可以给我一些code?

Can anyone give me some code ?

有些code将是成千上万线长(一个完整的实现,包括与各种设备特定的怪事买卖)。

"Some code" is going to be thousands of lines long (for a complete implementation, including dealing with various device-specific oddities).

欢迎您阅读关于这个问题 Android开发文档。

You are welcome to read the Android developer documentation on the subject.