在android中使用Device Camera时显示网格。

时间:2013-11-26 13:02:15

标签: android android-camera

我想在Android设备上使用相机时显示网格。如果您之前使用过Instagram,可能会看到它。如下图所示。如何在我的代码中为我的app.please实现它提供一些有用的链接,建议或相同的教程。

提前致谢:)

enter image description here

2 个答案:

答案 0 :(得分:0)

使用SurfaceView显示您的视频,例如,请查看此link;如何拍摄视频,以及如何使自定义SurfaceView显示网格的以下代码。

class MySurface extends SurfaceView implements SurfaceHolder.Callback,
        PreviewCallback {

    public MySurface(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

        // TODO draw grid
    }

    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
        // TODO handle camera frames

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {

        initCamera();
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {

        mCamera.startPreview();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

        releaseCamera();
    }
}

答案 1 :(得分:0)

你可以覆盖ondraw方法并使用它..

        Paint redPaint = new Paint();
          redPaint.setColor(Color.WHITE);
          redPaint.setStyle(Paint.Style.STROKE);
        canvas.drawLine((canvas.getWidth()/2)-size-20, (canvas.getHeight()/2)-size-20, (canvas.getWidth()/2)-size-20, (canvas.getHeight()/2)+size+20, redPaint);
        canvas.drawLine((canvas.getWidth()/2)+size+20, (canvas.getHeight()/2)-size-20, (canvas.getWidth()/2)-size-20, (canvas.getHeight()/2)-size-20, redPaint);
        canvas.drawLine((canvas.getWidth()/2)-size-20, (canvas.getHeight()/2)+size+20, (canvas.getWidth()/2)+size+20, (canvas.getHeight()/2)+size+20, redPaint);
        canvas.drawLine((canvas.getWidth()/2)+size+20, (canvas.getHeight()/2)+size+20, (canvas.getWidth()/2)+size+20, (canvas.getHeight()/2)-size-20, redPaint);
        canvas.drawLine((canvas.getWidth()/2)-(size/60), (canvas.getHeight()/2)-size-20, (canvas.getWidth()/2)+(size/60), (canvas.getHeight()/2)+size+20, redPaint);
        canvas.drawLine((canvas.getWidth()/2)+size+20, (canvas.getHeight()/2)-(size/60), (canvas.getWidth()/2)-size-20, (canvas.getHeight()/2)-(size/60), redPaint);