This is a mirror of official site: http://jasper-net.blogspot.com/

Android HTTP Camera Live Preview Tutorial

| Thursday, March 31, 2011
The Android SDK includes a Camera class that is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. It is a handy abstraction of the real hardware device. However, the SDK doesn't provide any camera emulation, something that makes testing camera enabled applications quite difficult. In this tutorial, I am going to show you how to use a web camera in order to obtain a live camera preview. 

What we are essentially going to do is setup a web camera to publish static images in a predefined URL and then grab these images from our application and present them as motion pictures. Note that this tutorial was inspired by a post named “Live Camera Previews in Android”.

Let's start by creating an Eclipse project under the name “AndroidHttpCameraProject” and an Activity named “MyCamAppActivity”. As a first step, I am going to show you how to use the SDK camera. You can find many resources on how to manipulate the camera, one of them being the CameraPreview class that is included in the SDK's samples. In short, we are going to extend the SurfaceView class and provide our implementation using the device's camera. Then, we use the setContentView method of our Activity in order to set the activity content to that specific View. Let's see what the two classes look like:

package com.javacodegeeks.android.camera;

import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.Window;

public class MyCamAppActivity extends Activity {
    
    private SurfaceView cameraPreview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        cameraPreview = new CameraPreview(this);
        
        setContentView(cameraPreview);
        
    }
    
}

Read more: Java code geeks

Posted via email from Jasper-net

0 comments: