更改油漆的alpha会更改整个油漆视图的Alpha

时间:2015-03-20 14:09:01

标签: java android

我正在处理一个绘图应用程序,当我试图通过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部分。

0 个答案:

没有答案