所以我有一個在容器上繪制路徑的代碼。
void paintWithPattern(
Canvas canvas, double x, double y, double width, double height) {
final maxDimension = max(width, height);
final stripeW = maxDimension / featuresCount / 6;
var step = stripeW * 9;
final paint = Paint()
..style = PaintingStyle.fill
..color = bgColor;
canvas.drawRect(Rect.fromLTWH(x, y, width, height), paint);
final rectStripesCount =
featuresCount * 2.5; // to make sure we cover the whole rectangle
final allStripesPath = Path();
for (var i = 1; i < rectStripesCount; i = 2) {
final stripePath = Path();
stripePath.moveTo(x - stripeW step, y);
stripePath.lineTo(x step, y);
stripePath.lineTo(x, y step);
stripePath.lineTo(x - stripeW, y step);
stripePath.close();
allStripesPath.addPath(stripePath, Offset.zero);
step = stripeW * 9;
}
paint
..style = PaintingStyle.fill
..color = fgColor;
canvas.drawPath(allStripesPath, paint);
}
在容器上繪制代碼的結果如下

我怎樣才能做到,所以它是由 Y 軸鏡像的?如下圖所示
uj5u.com熱心網友回復:
您可以使用負縮放和平移(以校正位置)來做到這一點,對于 Y 軸,如下所示:
canvas.scale(1, -1);
canvas.translate(0, -height);
canvas.drawPath(allStripesPath, paint);
對于 X 軸:
canvas.scale(-1, 1);
canvas.translate(-width, 0);
canvas.drawPath(allStripesPath, paint);
檔案:
https://api.flutter.dev/flutter/dart-ui/Canvas/scale.html
https://api.flutter.dev/flutter/dart-ui/Canvas/translate.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/395283.html
