You can easily implement a drawing view to your application. The drawing view lets you draw anything to the canvas using a lot of tools.
- Step 1. Add the JitPack repository to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
- Step 2. Add the dependency
dependencies {
implementation 'com.github.tolunaykan:DrawingView-Library-Android:1.0.0'
}
- Step 3. Add drawing view to your layout you want to display on
<com.tolunaykan.drawinglibrary.PaintView
android:id="@+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- Step 4. All you must to do add code below to your activity
PaintView paintView = findViewById(R.id.drawingView);
You can set brush preferences
paintView.setBrushColor(Color.BLACK);
paintView.setBrushSize(10);
Easily undoing and redoing your drawings
paintView.undoDrawing();
paintView.redoDrawing();
Choosing eraser or brush
paintView.enableEraser(); //Enable eraser
paintView.disableEraser(); //Enable brush
Listening to changes in canvas
paintView.addDrawingChangeListener(new DrawingChangeListener() {
@Override
public void onTouchStart(float x, float y) {
//paintView2.startTouch(x,y);
}
@Override
public void onDrawingChange(float x, float y) {
//paintView2.drawToCanvas(x,y);
}
});
You can draw to canvas without touching. Look at example at 4
paintView.startTouch(x,y); //Setting initial touch on canvas
paintView.drawToCanvas(x,y); //Drawing to canvas
paintView.setBackgroundColor(Color.WHITE); //Setting background color of the canvas
paintView.setTouchTolerance(2f); //Setting touch tolerance
paintView.clearCanvas(); //Clearing canvas
paintView.getCanvasBitmap(); //Getting image bitmap of canvas
- Tolunay Kandırmaz