Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - show grid lines on camera

I am newbie in android application development. I want to create an application that get stream from camera and show on SurfaceView or on FrameLayout.

I need an option shows above on streaming "Show Grid Lines", when user click on it grid lines will show on camera stream.

Can anybody help me that how can I show grid lines on camera streaming???

Any Help will be appreciable...

Thank you. Mohsin

like image 994
mohsin.mr Avatar asked Aug 01 '12 17:08

mohsin.mr


People also ask

How to turn off grid lines in Android OS 10 (Q)?

Please Note: Galaxy devices operating on Android OS 10 (Q) only have the option to use 3 x 3 Grid lines. 4 Choose between 3 x 3 or Square. If you would like to disable the grid, tap on Off

Can I use 3 x 3 grid lines on my Galaxy device?

Please Note: Galaxy devices operating on Android OS 11 (R) only have the option to use 3 x 3 Grid lines. Please Note: Galaxy devices operating on Android OS 10 (Q) only have the option to use 3 x 3 Grid lines.

How do I Turn Off the grid on my Galaxy device?

Please Note: Galaxy devices operating on Android OS 11 (R) only have the option to use 3 x 3 Grid lines. Please Note: Galaxy devices operating on Android OS 10 (Q) only have the option to use 3 x 3 Grid lines. 4 Choose between 3 x 3 or Square. If you would like to disable the grid, tap on Off


1 Answers

If you want to draw the lines dynamically as per your screen size then you should use the following code in your camera 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);
        }
    } 

You also need to add the following line in the constructor of your camera preview class:

this.setWillNotDraw(false);
like image 131
Jan Ziesse Avatar answered Sep 28 '22 22:09

Jan Ziesse