我正在处理一个绘图应用程序,当我试图通过mPaint.setAlpha((int)(255 -opaciyBrush * 2.53f))更改为绘制的alpha值时; 其中opacitybrush是从搜索栏获取值的整数。 是的,我每次在搜索栏的onStopTrackingTouch上初始化PaintingView类。 所以问题是,当我试图改变alpha的值时,它会改变画布上先前绘制的线的值。(即更改整个绘制视图的值) 我想解决这个问题,我的代码是
@SuppressLint("NewApi")
public PaintingView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
setDrawingCacheEnabled(true);
onCanvasInitialization();
}
private void onCanvasInitialization() {
mPaint = new Paint(Paint.DITHER_FLAG);
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setFilterBitmap(true);
mPaint.setColor(MainActivity.colorchanger);
mCanvas = new Canvas();
mPath = new Path();
Paint newPaint = new Paint(mPaint);
Container.paths.add(new Pair<Path, Paint>(mPath, newPaint));
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(widthBrush / 4 + 1);
mPaint.setAlpha((int) (255 - opacityBrush * 2.53f));
}
工作完美的接受alpha部分。