|
|
|
@ -23,7 +23,7 @@ import android.view.View;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @category: View实现涂鸦、撤销以及重做功能
|
|
|
|
|
* @category: View实现改变颜色、粗细、涂鸦、撤销以及重做功能
|
|
|
|
|
* @author: dingruihua
|
|
|
|
|
* @date: 2022.10.10
|
|
|
|
|
*
|
|
|
|
@ -34,7 +34,7 @@ public class PaintView extends View {
|
|
|
|
|
private Canvas mCanvas;
|
|
|
|
|
private Path mPath;
|
|
|
|
|
private Paint mBitmapPaint;
|
|
|
|
|
private Bitmap mBitmap;
|
|
|
|
|
public Bitmap mBitmap;
|
|
|
|
|
private Paint mPaint;
|
|
|
|
|
|
|
|
|
|
private ArrayList<DrawPath> savePath;
|
|
|
|
@ -47,6 +47,9 @@ public class PaintView extends View {
|
|
|
|
|
private int bitmapWidth;
|
|
|
|
|
private int bitmapHeight;
|
|
|
|
|
|
|
|
|
|
private int changed_width=0;
|
|
|
|
|
private int changed_color=0;
|
|
|
|
|
|
|
|
|
|
public PaintView(Context c) {
|
|
|
|
|
super(c);
|
|
|
|
|
//得到屏幕的分辨率
|
|
|
|
@ -80,7 +83,7 @@ public class PaintView extends View {
|
|
|
|
|
mPaint = new Paint();
|
|
|
|
|
mPaint.setAntiAlias(true);
|
|
|
|
|
mPaint.setDither(true);
|
|
|
|
|
mPaint.setColor(0xFF00FF00);
|
|
|
|
|
mPaint.setColor(0xFF000000);
|
|
|
|
|
mPaint.setStyle(Paint.Style.STROKE);
|
|
|
|
|
mPaint.setStrokeJoin(Paint.Join.ROUND);
|
|
|
|
|
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
|
@ -101,7 +104,29 @@ public class PaintView extends View {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void changewidth(){
|
|
|
|
|
if (changed_width==0) {
|
|
|
|
|
mPaint.setStrokeWidth(50);
|
|
|
|
|
changed_width = 1;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
mPaint.setStrokeWidth(10);
|
|
|
|
|
changed_width = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void changecolor(){
|
|
|
|
|
if (changed_color==0) {
|
|
|
|
|
mPaint.setColor(0xFFFF0000);
|
|
|
|
|
changed_color = 1;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
mPaint.setColor(0xFF000000);
|
|
|
|
|
changed_color = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
|
|
|
|
|
@ -126,8 +151,16 @@ public class PaintView extends View {
|
|
|
|
|
|
|
|
|
|
System.out.println(savePath.size()+"--------------");
|
|
|
|
|
if(savePath != null && savePath.size() > 0){
|
|
|
|
|
//调用初始化画布函数以清空画布
|
|
|
|
|
initCanvas();
|
|
|
|
|
//清空画布
|
|
|
|
|
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
|
|
|
|
|
//画布大小
|
|
|
|
|
mBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight,
|
|
|
|
|
Bitmap.Config.RGB_565);
|
|
|
|
|
mCanvas = new Canvas(mBitmap); //所有mCanvas画的东西都被保存在了mBitmap中
|
|
|
|
|
|
|
|
|
|
mCanvas.drawColor(Color.WHITE);
|
|
|
|
|
mPath = new Path();
|
|
|
|
|
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
|
|
|
|
|
|
|
|
|
|
//将路径保存列表中的最后一个元素删除 ,并将其保存在路径删除列表中
|
|
|
|
|
DrawPath drawPath = savePath.get(savePath.size() - 1);
|
|
|
|
@ -168,52 +201,15 @@ public class PaintView extends View {
|
|
|
|
|
public void removeAllPaint(){
|
|
|
|
|
//调用初始化画布函数以清空画布
|
|
|
|
|
initCanvas();
|
|
|
|
|
changed_color=0;
|
|
|
|
|
changed_width=0;
|
|
|
|
|
invalidate();//刷新
|
|
|
|
|
savePath.clear();
|
|
|
|
|
deletePath.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 保存所绘图形
|
|
|
|
|
* 返回绘图文件的存储路径
|
|
|
|
|
*
|
|
|
|
|
public String saveBitmap(){
|
|
|
|
|
//获得系统当前时间,并以该时间作为文件名
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmss");
|
|
|
|
|
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
|
|
|
|
|
String str = formatter.format(curDate);
|
|
|
|
|
String paintPath = "";
|
|
|
|
|
str = str + "paint.png";
|
|
|
|
|
File dir = new File("/sdcard/notes/");
|
|
|
|
|
File file = new File("/sdcard/notes/",str);
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
dir.mkdir();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if(file.exists()){
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
|
|
|
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
//保存绘图文件路径
|
|
|
|
|
paintPath = "/sdcard/notes/" + str;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return paintPath;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void touch_start(float x, float y) {
|
|
|
|
|