简体   繁体   English

Android - 拍摄照片

[英]Android - Capture photo

In my application, i have to implement native camera activity where i have to launch the camera and take photo. 在我的应用程序中,我必须实现原生相机活动,我必须启动相机并拍照。

In detail, my application containing, One TextView (at top) to display activity name and one Button (At bottom) and in Middle Area of the screen, Camera preview should be viewed..When user click on that Button, Snaps should be clicked and display it into Imageview of another activity. 详细地说,我的应用程序包含,One TextView(在顶部)显示活动名称和一个按钮(在底部)和屏幕的中间区域,应该查看相机预览..当用户单击该按钮时,应单击快照并将其显示在另一个活动的Imageview中。

I know that the following approach is used: 我知道使用以下方法:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult( intent, 0 );

But this approach if i used then my textview and button view is not displayed. 但是如果我使用这种方法则不会显示我的textview和按钮视图。

(Pls note that: I am using Android SDK 1.5 with HTC Hero) (请注意:我正在使用Android SDK 1.5和HTC Hero)

pls help me by suggestion of any article, site, or pdf. 请通过任何文章,网站或pdf的建议来帮助我。

thanx, paresh thanx,paresh

If you are trying to use the native camera, once the native camera is called it will control your view. 如果您尝试使用本机相机,一旦调用本机相机,它将控制您的视图。 However if you want to implement your own camera, then such a layout would be possible. 但是,如果您想要实现自己的相机,那么这样的布局是可能的。 Some good examples can be found here: 这里可以找到一些很好的例子:

Goodluck! 祝好运!

All the instructions are at the JavaDoc of android.hardware.Camera at http://developer.android.com/reference/android/hardware/Camera.html : 所有说明都在http://developer.android.com/reference/android/hardware/Camera.html的android.hardware.Camera的JavaDoc中:

  1. Obtain an instance of Camera from open(). 从open()获取Camera实例。
  2. Get existing (default) settings with getParameters(). 使用getParameters()获取现有(默认)设置。
  3. If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters). 如有必要,修改返回的Camera.Parameters对象并调用setParameters(Camera.Parameters)。
  4. If desired, call setDisplayOrientation(int). 如果需要,请调用setDisplayOrientation(int)。
  5. Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder). 重要提示:将完全初始化的SurfaceHolder传递给setPreviewDisplay(SurfaceHolder)。 Without a surface, the camera will be unable to start the preview. 没有表面,相机将无法启动预览。
  6. Important: Call startPreview() to start updating the preview surface. 重要提示:调用startPreview()开始更新预览曲面。 Preview must be started before you can take a picture. 必须先开始预览才能拍照。
  7. When you want, call takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback) to capture a photo. 如果需要,可以调用takePicture(Camera.ShutterCallback,Camera.PictureCallback,Camera.PictureCallback,Camera.PictureCallback)来捕获照片。 Wait for the callbacks to provide the actual image data. 等待回调提供实际的图像数据。
  8. After taking a picture, preview display will have stopped. 拍照后,预览显示将停止。 To take more photos, call startPreview() again first. 要拍摄更多照片,请先再次调用startPreview()。
  9. Call stopPreview() to stop updating the preview surface. 调用stopPreview()以停止更新预览表面。
  10. Important: Call release() to release the camera for use by other applications. 重要事项:调用release()以释放相机以供其他应用程序使用。 Applications should release the camera immediately in onPause() (and re-open() it in onResume()). 应用程序应立即在onPause()中释放相机(并在onResume()中重新打开()。

    The SurfaceHolder is ususally implemented using SurfaceView SurfaceHolder通常使用SurfaceView实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM