Domanda

This is the onDraw method I have:

protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(bitmap, 0, 0, mBitmapPaint); // Deseneaza Bitmapul mutabil

        if (shapes.size() > 0) {
        for (ShapeFromLines shapesfromline : shapes) {
            if (shapesfromline.size() > 1) {
                LogService.log("", "shapes: " + shapesfromline.size());
                float startx, starty;
                startx = shapesfromline.get(0).stopX;
                starty = shapesfromline.get(0).stopY;
                for (int i = 1; i < shapesfromline.size(); i++) {
                    LogService.log("", "----size color in ondraw: " + shapesfromline.get(i).getPaint().getColor());
                    canvas.drawLine(startx, starty, shapesfromline.get(i).getStopX(), shapesfromline.get(i).stopY, shapesfromline.get(i).getPaint());
                    LogService.log("", "shapes: drawn");
                    startx = shapesfromline.get(i).stopX;
                    starty = shapesfromline.get(i).stopY;
                }
            }
        }

    }
        for (int i = 0; i < bitmaps.size(); i++) {
            if ((bitmaps.get(i).bitmap != null)) {
                canvas.save();
                canvas.rotate(bitmaps.get(i).rectrotateVal, bitmaps.get(i).pX + (bitmaps.get(i).bitmap.getWidth() / 2), bitmaps.get(i).pY + (bitmaps.get(i).bitmap.getHeight() / 2));
                mBitmapPaint.setAlpha(bitmaps.get(i).alpha);
                // canvas.drawRect(bitmaps.get(i).rect, cPaint);
                canvas.drawBitmap(bitmaps.get(i).bitmap, bitmaps.get(i).pX, bitmaps.get(i).pY, mBitmapPaint);
                canvas.restore();
            }
        }
        mBitmapPaint.setAlpha(255);
        canvas.drawPath(mPath, paint);
    }
}

As you can I I have some Shapes (each shape is created from an arraylist of points named ShapesFromLines. Now the first point of my shape is from the touchDown (ontouchevent), where I save the current location. then the other points are saved on touch up. When you press the screen the first time it will draw a point, then the second time, it will connect those 2 points, then 3, etc. I save the X,Y and Paint on each point. As you can see, I have a logservice on draw, which returns the paint value for those points. Now I have a function with a color picker that changes the color of the current path. But this manages to change the color of all my straight lines. Now I checked, when I want to add a picture, the main paint is set to transparent. And then the lines are transparent, but the points (that should be connected) have the right color. Any ideea what could be wrong?

È stato utile?

Soluzione

when I created the objects, i passed the paint as a reference, and when changing it, it would change the paint also. I did this to fix it:

Paint linepaint = new Paint();
        linepaint.setColor(paint.getColor());
        linepaint.setAlpha(paint.getAlpha());
        linepaint.setAntiAlias(true);
        linepaint.setDither(true);
        linepaint.setStyle(paint.getStyle());
        linepaint.setStrokeJoin(paint.getStrokeJoin());
        linepaint.setStrokeCap(paint.getStrokeCap());
        linepaint.setStrokeWidth(paint.getStrokeWidth());
pointsForLines.add(new Points(stopX, stopY, linepaint));

Where paint was the global paint I was using before

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top