scaling and centering a path

2019-03-03 07:30发布

问题:

I have a Path in Android and I want to stretch it to the full size of the canvas (screen size) and center it, i want to do this in my onDraw() event. The effect I'm going for is zooming in on the drawing until it matches the screen size.

Btw, this is a View that is drawed on as the path is created from an external hardware device similar to a wacom tablet.

So, if someone draws on the tablet lets say, the letter "a" at the top, the entire screen would show the large letter "o", ( https://snag.gy/nWB730.jpg ) but, if someone also then drew another one at the bottom, it would show the o at actual size at the top with the o at actual size at the bottom. (https://snag.gy/Mo49Z7.jpg) the screenshots are from iOS. I have it working on that platform.

Here's what I have so far

int width = Resources.getSystem().getDisplayMetrics().widthPixels;
int height = Resources.getSystem().getDisplayMetrics().heightPixels;

 scaleMatrix.postScale(pathBounds.width()/width, pathBounds.height()/height);

 drawPath.transform(scaleMatrix);
canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
canvas.drawPath(drawPath, drawPaint);

It kind of stretches, but it doesn't center and it doesn't scale the top and bottom like the second iOS screenshot. Help is appreciated.