1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
public class MonAppli extends Activity
{
private Preview mPreview = null ;
/** Called when the activity is first created.*/
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState) ;
requestWindowFeature(Window.FEATURE_NO_TITLE) ; // Hide the window title.
AugmentedRealityLayer augrea = new AugmentedRealityLayer(this) ;
mPreview = new Preview(this, augrea, 1) ; // Create our Preview view and set it as the content of our activity.
FrameLayout frameLayout = new FrameLayout(this) ; // L'affichage en deux couches
frameLayout.addView(mPreview) ;
frameLayout.addView(augrea) ;
setContentView(frameLayout) ;
}
}
public class AugmentedRealityLayer extends View
{
public AugmentedRealityLayer(Context context)
{
super(context) ;
}
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas) ;
// J'affiche ici ce que je veux.
}
}
public class Preview extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder mHolder = null ;
private Camera mCamera = null ;
public Preview(Context context, AugmentedRealityLayer augrea, int nbCPU)
{
super(context) ;
// Install a SurfaceHolder.Callback so we get notified when the underlying surface is created and destroyed.
mHolder = getHolder() ;
mHolder.addCallback(this) ;
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS) ;
}
public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open() ;
mCamera.setPreviewCallback(
new PreviewCallback()
{
public void onPreviewFrame(final byte[] data, final Camera camera)
{
// J'analyse mon flux vidéo ici grâce à ce callback.
}
}
) ;
}
... // Le code classique d'affichage dans la doc Android.
} |
Partager