Android - show mesh lines on camera

I am new to Android app development. I want to create an application that will receive a stream from the camera and show on SurfaceView or FrameLayout.

I need the option shown above when streaming "Show Grid Lines", when the user clicks on it, the grid lines will be displayed in the camera stream.

Can anyone help me how to show the mesh lines when streaming the camera?

Any help would be noticeable ...

Thank. Muhsin

+5
source share
2 answers

If you want to dynamically draw lines depending on the size of the screen, you can use this by adding it to the camera's preview class.

    @Override  
    protected void onDraw(Canvas canvas)  
    { 
        if(grid){
        //  Find Screen size first  
        DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();  
        int screenWidth = metrics.widthPixels;  
        int screenHeight = (int) (metrics.heightPixels*0.9);  

        //  Set paint options  
        paint.setAntiAlias(true);  
        paint.setStrokeWidth(3);  
        paint.setStyle(Paint.Style.STROKE);  
        paint.setColor(Color.argb(255, 255, 255, 255));  

        canvas.drawLine((screenWidth/3)*2,0,(screenWidth/3)*2,screenHeight,paint);
        canvas.drawLine((screenWidth/3),0,(screenWidth/3),screenHeight,paint);
        canvas.drawLine(0,(screenHeight/3)*2,screenWidth,(screenHeight/3)*2,paint);
        canvas.drawLine(0,(screenHeight/3),screenWidth,(screenHeight/3),paint);
        }
    } 

:

this.setWillNotDraw(false);
+11

, . , , :

http://developer.android.com/guide/topics/media/camera.html#custom-camera

, XML- . RelativeLayout, (, ) .

XML, , . FrameLayout ( , ). ImageView .

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

  <FrameLayout
    android:id="@+id/camera_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

  <ImageView
    android:id="@+id/grid"
    android:src="@drawable/your_grid_drawable"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

</RelativeLayout>

, , . RelativeView , .

+3

All Articles