如何拍张照片没有意图并没有在Android中的任何视图窗口并没有、视图、意图、窗口

2023-09-06 07:57:36 作者:愿岁月可回首

好日子好,我试图找出如何利用由pressing按钮的图片,而不显示的任何preVIEW。我们的想法是,我要采取和保存的照片,但照片的没有视觉preVIEW之前或之后。到目前为止,我能够得到code拍照,并将它们保存到磁盘没有任何问题,但我似乎无法做到这一点没有surfaceview或preVIEW。

Good day all, I am trying to figure out how to take a picture by pressing a button, without any preview showing up. The idea is, I want a picture to be taken and saved, but no visual preview of the photo before or afterwards. So far, I am able to get the code to take pictures and save them to the disk without any problems, but I cannot seem to do it without a surfaceview or preview.

下面是我的一些code的:

Here is some of my code:

主要活动:

public class MainActivity extends Activity implements OnClickListener {

        private Camera cameraObject;
        private ShowCamera showCamera;
        private Button NOPE;

        //Check if camera is avail:
        public static Camera isCameraAvailiable(){
            Camera object = null;
            try {
              object = Camera.open();
                L.m("Camera Open");
            } catch (Exception e) {
              L.m(e.toString());
            } return object; 
        }

       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          //Opens up the camera
          cameraObject = isCameraAvailiable();

          //Sets the resolution for the camera (Excluded from code here)
          setCameraResolution();

          //Button for taking photos
          NOPE = (Button) findViewById(R.id.button_capture);
          NOPE.setOnClickListener(this);

          //THIS SECTION OF CODE HERE I can't get it to work without it as this creates a view/ preview for the camera
          showCamera = new ShowCamera(this, cameraObject);
          FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
          preview.addView(showCamera);
       }

        public void snapIt(View view){
           cameraObject.takePicture(null, null, new PhotoHandler(getApplicationContext()));
       }

        public void onClick(View view) {
            switch (view.getId()){
            case R.id.button_capture:
                    snapIt(view);
            }
        }   
    }

照片处理类:

public class PhotoHandler implements PictureCallback {

    private final Context context;

    public PhotoHandler(Context context) {
        this.context = context;
    }

    public void onPictureTaken(byte[] data, Camera camera) {

        File pictureFileDir = getDir();
        if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
            //I removed unnecessary code here, but this is where I write to disk, which works fine.
        }
    }

我遇到的问题是,我不能实际上是通过相机拍摄的照片,除非我有code约preview.addView(showCamera);.该ShowCamera类仅仅是一个增加了一个面视图查看图片,而他们正在采取:

The problem I am having is that I CANNOT actually take a photo via the camera unless I have the code about preview.addView(showCamera);. The ShowCamera class is merely one that adds a surface view for viewing the pictures while they are being taken:

public class ShowCamera extends SurfaceView implements SurfaceHolder.Callback

任何人有什么想法?可以这样做?

Anyone have any ideas? Can this be done?

有人问这里一个非常类似的问题:Taking图片而不SurfaceView或没有照片意向活动,但没有成功。我认为我是一个类似的路径上,因为他们。

Someone asked an EXTREMELY similar question here: Taking picture without SurfaceView or without Photo Intent Activity , but without any success. I think I'm on a similar path as they were.

推荐答案

我也有同样的问题,我用思想促进在SurficeView新视图,以便surficeView未见解决。我通过搜索其他的解决办法,但都没有成功花费相当的时间。

I have the same problem and I solve it by puting new view over the SurficeView so surficeView was not seen. I spend quite a time by searching for other solution but without success.