- rohit vobbilisetty. what is the camera api capture photos capture videos camera api - android2

19
Camera API - Android - Rohit Vobbilisetty

Upload: abigayle-philips

Post on 28-Mar-2015

285 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android

- Rohit Vobbilisetty

Page 2: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 2

What is the Camera APICapture PhotosCapture Videos

Page 3: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 3

Before startingDeclare the permissions in the Android

Manifest

Camera Usage:<uses-permission android:name="android.permission.CAMERA" />

Camera Features:<uses-feature android:name="android.hardware.camera" />

Camera Auto-Focus:<uses-feature android:name="android.hardware.camera.autofocus" />

Write to External Storage:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Page 4: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 4

Camera APIOverview

Primary API for controlling device cameras. Used to capture pictures and videos.

Package: android.hardware.Camera

Methods:Camera.open() – Obtain an instancestartPreview() – Starts the Camera previewtakePicture() – Takes a picturestopPreview() – Stops the Camera previewrelease() – Releases the cameragetParameters() – Zoom, Image Quality, Location Information

Page 5: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

5

Camera API – Capture Photo

Detect and Access CameraCreate a Preview ClassBuild a Preview LayoutSetup Listeners for CaptureCapture and Save FilesRelease the Camera

Camera API - Android

Page 6: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 6

Camera API – Capture PhotoDetect and Access Camera

Check for an existing Camera and obtain reference.

Detect

if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){ // this device has a camera return true;} else { // no camera on this device return false;}

AccessUse camera.open() to obtain a reference to the Camera. An exception implies Camera is in use or does not exist.

Camera c = null; try { c = Camera.open(); // attempt to get a Camera instance } catch (Exception e){ // Camera is not available (in use or does not exist) }

Use Camera.getParameters() to obtain the Camera capabilities.

Page 7: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 7

Camera API – Capture PhotoCreate a Preview Class and Preview Layout

Surface View (android.view.SurfaceView) Provides a dedicated surface Is Z- ordered, so useful for overlaying

buttons over this surface

SurfaceHolder.Callback (interface)(android.view.SurfaceHolder.Callback) Receives information about changes to

the surface (SurfaceView). Methods:

surfaceCreated()surfaceChanged() surfaceDestroyed()

Page 8: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 8

Camera API – Capture PhotoCreate a Preview Class and Preview Layout

A Preview Class is a SurfaceView that can display live image data coming directly from the Camera.

Create a class that extends SurfaceView and implements Surfaceholder.Callback..Override the methods surfaceCreated(), surfaceChanged() and surfaceDestroyed()

Preview Layout:Relative Layout with a Frame Layout to display the Camera Preview, and a Button which will trigger the capture.

Page 9: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 9

Camera API – Capture PhotoSetup Listeners for Capture

Attach an OnClick Listener to the button. This listener should call takePicture().

NOTE: The method takePicture() requires the instance of PictureCallback as an argument.

Page 10: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 10

Camera API – Capture PhotoCapture and Save Files

Create an instance of PictureCallback() and override the method onPictureTaken(). This method includes the logic to save the image to a file.

Once the picture is taken, the method onPictureTaken() is called.

Page 11: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 11

Camera API – Capture PhotoRelease the Camera

Release the Camera by calling Camera.release(), once the application does not require it or on application exit.

Page 12: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 12

Camera API – Capture PhotoOrientation and Rotation

The Camera Preview’s Orientation depends on the Orientation and Rotation of the device.

Orientation (Portrait OR Landscape)getResources().getConfiguration().orientation

Rotationactivity.getWindowManager().getDefaultDisplay().getRotation();Returns: ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270

Set the Camera Preview Orientation using Camera.setDisplayOrientation(angle).

Page 13: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 13

Camera API – Capture PhotoOrientation and Rotation

Orientation: LandscapeRotation: ROTATION_270

Fix:Set the Camera Preview Orientation using Camera.setDisplayOrientation()

If(Orientation=Landscape & Rotation=ROTATION_270){Camera.setDisplayOrientation(180).}

Page 14: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 14

Camera API – Capture PhotoDiagram

Camera Preview

surfaceCreated()

surfaceChanged()

surfaceDestroyed()

Activity

new CameraPreview(Camera)Button Event Handler

Layout FrameLayout and Button

Device Camera

Page 15: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 15

Additional FeaturesZoom (API level 8)GPS DataVideo Snapshot (API level 14)Face Detection (API level 14)

Page 16: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 16

Demo

Page 17: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 17

ReferencesAndroid Developer – Camera API

http://developer.android.com/guide/topics/media/camera.html

StackOverflowVogella.com – Camera API

http://www.vogella.com/articles/AndroidCamera/article.html

Page 18: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 18

Questions ??

Page 19: - Rohit Vobbilisetty. What is the Camera API Capture Photos Capture Videos Camera API - Android2

Camera API - Android 19

Thank You