2

我有以下用于访问相机预览的代码我想在预览图片的上角显示一些文本我该怎么做?

package com.gps.ro.capturetest;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class CaptureTestActivity extends Activity implements SurfaceHolder.Callback {
         SurfaceHolder mSurfaceHolder;
        SurfaceView mSurfaceView;
        public Camera mCamera;
        boolean mPreviewRunning;
        Canvas test;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.main);
        mSurfaceView = (SurfaceView) findViewById(R.id.camera_surface);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);




    }

    public void surfaceChanged(SurfaceHolder arg0, int arg1, int h, int w) {
        // TODO Auto-generated method stub
        if (mPreviewRunning) {
                            mCamera.stopPreview();
                        }
                        Camera.Parameters p = mCamera.getParameters();
                        mCamera.setDisplayOrientation(90);
                        p.setPreviewSize(h, w);
                        p.set("orientation", "portrait");

                        //p.setPreviewSize(w, h);
                        mCamera.setParameters(p);
                        try {
                            mCamera.setPreviewDisplay(arg0);

                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        mCamera.startPreview();
                        mPreviewRunning = true;

    }

    public void surfaceCreated(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
        mCamera = Camera.open();
    }

    public void surfaceDestroyed(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
                mCamera.stopPreview();
                mPreviewRunning = false;
                mCamera.release();
    }

    public void Trigger(View V)
    {
        ShutterCallback shutterCallback = new ShutterCallback() {
            public void onShutter() {
                Log.d("DHA", "onShutter'd");
            }
        };

        PictureCallback rawCallback = new PictureCallback() {
            public void onPictureTaken(byte[] data, Camera camera) {
                Log.d("DHA", "onPictureTaken - raw");
            }


        };
        Log.w("DHA", "Intra aici!");
        mCamera.takePicture(shutterCallback, rawCallback, null);

    }







}
4

1 回答 1

2

在表面视图之上创建另一个视图,并在该视图中绘制您的装饰。例如,您可以使用 FrameLayout 并在其中使用 SurfaceView,然后在预览顶部显示您想要的视图。

于 2012-04-24T15:23:46.173 回答