A simple way to draw smooth line on Android.
- Change stroke color
- Change stroke width
- Undo
- Clear all drawings
- Eraser drawing
- Get final bitmap
In Android Studio, just import module wtdrawing
. In other IDE, you should copy WTBezierPath.java
and WTDrawingView.java
into your project.
<com.water.wtdrawing.WTDrawingView
android:id="@+id/wtDrawingView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Note: layout_width
and layout_height
can not be wrap_content
.
int width = width you want;
int height = height you want;
WTDrawingView wtDrawingView = new WTDrawingView(context,width,height);
Then add WTDrawingView instance to your view group.
wtDrawingView.undo();
wtDrawingView.clear();
wtDrawingView.setEraserMode(true);
wtDrawingView.setStrokeWidth(5.0f); // 5.0f is a dp value.
Default stroke width is 2.0(dp).
wtDrawingView.setStrokeColor(Color.RED);
Default stroke color is black.
wtDrawingView.setEraserWidth(20.0f); // 20.0f is a dp value.
Default eraser width is 20(dp).
int backgroundColor = Color.WHITE;
Bitmap bitmap = wtDrawingView.getBitmap(backgroundColor);
1.0.1
- add getBitmap method to retrieve final bitmap
- Use
dirty rect
to improve drawing performance