============问题描述============
//画笔,定义绘制属性 private Paint myPaint; private Paint mBitmapPaint; // 绘制路径 private Path myPath; // 画布及其底层位图 private Bitmap myBitmap0; private Bitmap myBitmap1; private Canvas myCanvas; public MyPaintView(Context context, AttributeSet attrs){ super(context, attrs); myBitmap0 = BitmapFactory.decodeFile("/storage/sdcard/a.png").copy(Bitmap.Config.ARGB_8888, true); myBitmap1 = Bitmap.createBitmap(myBitmap0); if(i == 0){ initialize(); }else if(i == 1){ initWhite(); } // 开启线程 new Thread(this).start(); } public void initialize(){ // 绘制自由曲线用的画笔 myPaint = new Paint(); myPaint.setAntiAlias(true); myPaint.setDither(true); myPaint.setColor(RGBColor.getColor()); myPaint.setStyle(Paint.Style.STROKE); myPaint.setStrokeJoin(Paint.Join.ROUND); myPaint.setStrokeCap(Paint.Cap.ROUND); myPaint.setStrokeWidth(RGBColor.getFontSize()); myPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } @Override protected void onDraw(Canvas canvas){ super.onDraw(canvas); // 背景颜色 canvas.drawColor(R.color.white); canvas.drawBitmap(myBitmap1, 0, 0, mBitmapPaint); canvas.drawPath(myPath, myPaint); myCanvas = new Canvas(myBitmap1); } /** * 图片旋转 * */ public void picPost(int nPostExtent){ matrix.reset(); matrix.postScale(Scale, Scale); matrix.postRotate(nPostExtent); // 下面这句话如果把myBitmap1都改为myBitmap0的话顺时针和逆时针旋转都没有问题,现在需要用myBitmap1,是因为在这个位图上面先涂鸦了再旋转的话就会清空以前涂鸦内容,所以选用myBitmap1,但是用它的话只能朝着一个方向旋转,先顺时针完了,逆时针就回不来了 myBitmap1 = Bitmap.createBitmap(myBitmap1, 0, 0, myBitmap1.getWidth(), myBitmap1.getHeight(), matrix, true); }
============解决方案1============
哦,不是90度角呀,45度角那回不来了。因为图片是在不断变大了,右上角不断填充了白色区域。
把path存起来,底图不变,每次画图都是底图+path
或者把path画在一个canvas上,把底图在另一个bitmap上,两个叠加。
时间: 2024-10-06 00:45:21