取并保存图像按钮preSS [英] Take and save picture on button press

查看:140
本文介绍了取并保存图像按钮preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个Android应用程序,它利用用户所拍摄的图像作为一个更大过程的一部分。到目前为止,我的XML布局有一个SurfaceView的按钮和一个RelativeLayout的内部。我已经成功地让相机preVIEW显示在SurfaceView但我坚持就如何拍摄一张照片,并将其保存在用户presses按钮。

I'm creating an Android application which uses user captured images as part of a larger process. So far my XML layout has a SurfaceView and Button inside a RelativeLayout. I've managed to get the camera preview to show on the SurfaceView but I'm stuck on how to take a picture and save it when a user presses the button.

我的类文件看起来像相机preVIEW API演示: <一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Camera$p$pview.html">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Camera$p$pview.html

My class file looks something like the CameraPreview API demo: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

在理想情况下,当按钮是pressed相机应该自动对焦,拍摄照片(与clicky声音),将其保存到 /data/data/app_package_structure/files/file_name.jpg ,然后会弹出一个面包,告诉他们的形象已保存的用户。

Ideally, when the button it pressed the camera should autofocus, snap a picture (with the clicky sound), save it to /data/data/app_package_structure/files/file_name.jpg, then pop up a Toast to tell the user their image has been saved.

任何帮助是非常AP preciated:)

Any help is much appreciated :)

推荐答案

我觉得CommonsWare真的已经回答了大部分这个问题,但是这可能适用于自动对焦和快门声。这是一种猜测,因为我不是在一台机器,我可以编译/测试任何这一点。

I think CommonsWare has really already answered most of this question, but this might work for the auto focus and the shutter sound. This is a guess, since I'm not at a machine where I can compile/test any of this.

在您的按钮 - preSS处理code,我相信你应该调用(可能通过消息传递)

In your button-press-handling code, I believe you should call (possibly by message passing)

camera.autoFocus(new Camera.AutoFocusCallback() {
  Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() {
    public void onShutter() {
      // Play your sound here.
    }
  };
  public void onAutoFocus(boolean success, Camera camera) {
    camera.takePicture(shutterCallback, null, photoCallback);
  }
});  

其中,相机是你的相机对象, photoCallback 是相同CommonsWare的例子。

where camera is your camera object, and photoCallback is the same as in CommonsWare's example.

究竟是什么,你被卡住了?

Exactly what is it that you are stuck on?

哦,不要忘记添加&LT;使用特征&GT; 标记 android.hardware.camera.autofocus 。 :)

Oh, and don't forget to add the <uses-feature> tag android.hardware.camera.autofocus. :)

这篇关于取并保存图像按钮preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆