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
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
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.
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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With