渲染相机图像上的动态文本

时间:2012-01-17 10:05:44

标签: android

我想在相机的4个角上显示4个文本视图。该文本将从数据库中检索,即文本视图的输入将动态给出。 任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您可以动态创建线性布局并向其添加textview ...同样可以添加到相机视图(SurfaceView)。从您的Activity开始跟随calss并调用DisplayText()函数,无论您想要更新摄像机视图中的文本。

public class CameraApps extends SurfaceView implements Camera.PreviewCallback
{
    private     Context DisCtx                  = null;
    private     Camera camera                   = null;

    public OTPCamera(Context ctx)
    {
        super(ctx);
        this.DisCtx             = ctx;
        camera = Camera.open();
        camera.setPreviewCallback(this);
        camera.setPreviewDisplay(getHolder());
        camera.startPreview();
    }
    public void DisplayText(String text1,String text2,String text3,String text4)
     {
        LinearLayout.LayoutParams layoutpar = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);

        TextView txtview = new TextView(DisCtx);
        txtview.setText(text1);
        txtview.setTextSize(25);
        txtview.setGravity(Gravity.TOP | Gravity.LEFT);
        txtview.setTextColor(Color.RED);
        ((Activity)DisCtx).addContentView(txtview, layoutpar);



         TextView txtview1 = new TextView(DisCtx);
         txtview1.setText(text2);
         txtview1.setTextSize(25);
         txtview1.setGravity(Gravity.TOP | Gravity.RIGHT);
         txtview1.setTextColor(Color.RED);
         ((Activity)DisCtx).addContentView(txtview1, layoutpar);

         TextView txtview2 = new TextView(DisCtx);
         txtview2.setText(text3);
         txtview2.setTextSize(25);
         txtview2.setGravity(Gravity.BOTTOM | Gravity.LEFT);
         txtview2.setTextColor(Color.RED);
         ((Activity)DisCtx).addContentView(txtview2, layoutpar);

         TextView txtview3 = new TextView(DisCtx);
         txtview3.setText(text4);
         txtview3.setTextSize(25);
         txtview3.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
         txtview3.setTextColor(Color.RED);
         ((Activity)DisCtx).addContentView(txtview3, layoutpar);



    }

}