Я не мог изменить размер собственной кисти - PullRequest
0 голосов
/ 02 августа 2020

Я хотел и сделал специальный бюст sh, но проблема в том, что когда я меняю размер своего sh, размер других рисунков, которые я рисую, меняется.

Я хочу , как я могу предотвратить изменение размеров других моих чертежей, если я хочу изменить размер моего брюшка sh?

Я написал код в области, где я буду рисовать, то есть onDraw.

@Override
protected void onDraw(Canvas canvas) {
for (LinePath linePath : mDrawnPaths) {
    canvas.drawPath(linePath.getDrawPath(), linePath.getDrawPaint());

//I pasted the same code here
//And I fix: pathMeasure = new PathMeasure(LinePath.getDrawPath(), false);


}
canvas.drawPath(mPath, mDrawPaint);

Bitmap mBitmap = getScaledBitmap();

// find the center of the bitmap.
centerX = mBitmap.getWidth() / 2;
centerY = mBitmap.getHeight() / 2;

// wrap the path with a measurement tool for paths - PathMeasure
pathMeasure = new PathMeasure(mPath, false);

// initialize the distance to the center of the bitmap.
distance = mBitmap.getWidth() / 2;

// initialize position and slope buffers.
position = new float[2];
slope = new float[2];

// draw so long as the distance traveled on the path isn't longer than
// the total distance of the path.
while (distance < pathMeasure.getLength())
{
    // grab the position & slope (tangent) on a particular distance along the path.
    pathMeasure.getPosTan(distance, position, slope);

    // convert the vector to a degree.
    slopeDegree = (float)((Math.atan2(slope[1], slope[0]) * 180f) / Math.PI);

    // preserve the current state of the canvas
    canvas.save();

    // translate the canvas to the position on the path.
    canvas.translate(position[0] - centerX, position[1] - centerY);

    // rotate the canvas around the center of the bitmap the amount of degrees needed.
    canvas.rotate(slopeDegree, centerX, centerY);

    // draw the bitmap
    canvas.drawBitmap(mBitmap, 0, 0,DrawPaint);

    // revert the bitmap to the previous state
    canvas.restore();

    // increase the distance by the bitmap's width + the desired margin.
    distance += mBitmap.getWidth() + 10;
}
}

private Bitmap getScaledBitmap()
{
Bitmap mBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.heart);
// no bitmap or resId, return null (no special handing of this! add if you like).
if (mBitmap == null)
    return null;

// width / height of the bitmap[
float width = mBitmap.getWidth();
float height = mBitmap.getHeight();

// ratio of the bitmap
float ratio = width / height;

// set the height of the bitmap to the width of the path (from the paint object).
float scaledHeight = DrawPaint.getStrokeWidth();

// to maintain aspect ratio of the bitmap, use the height * ratio for the width.
float scaledWidth = scaledHeight * ratio;

// return the generated bitmap, scaled to the correct size.
}

Нажмите, чтобы увидеть картинку

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...