我目前正在Flutter中编写一个室内导航应用程序,而在Flutter和Dart中还很新。为此,我使用并希望基于Android的mapsforge扩展库mapsforge_flutter。使用mapsforge_flutter,我可以下载OpenStreetMap地图,然后在手机上渲染这些地图。问题在于,地图上的线条看起来像这样像素化:
AntiAliasing尚未在mapsforge_flutter中实现,因此我认为问题可能出在这里。在原始的mapsforge库中,地图看起来没有像素化。
AA是通过以下方式在原始库中实现的:
# Build the program, which needs a full C toolchain.
FROM ubuntu:18.04 AS builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
build-essential
WORKDIR /app
COPY hello.c .
RUN gcc -static -o hello hello.c
# Then create an image that _only_ contains the static binary.
FROM scratch
COPY --from=builder /app/hello /hello
ENTRYPOINT ["/hello"]
在mapsforge_flutter中有两个类:Mapcanvas和Fluttercanvas具有以下方法,必须实现:
// in Parameters.java:
//If true will use anti-aliasing in rendering.
public static boolean ANTI_ALIASING = true;
// in AndroidPaint.java:
AndroidPaint() {
paint = new android.graphics.Paint();
this.paint.setAntiAlias(Parameters.ANTI_ALIASING);
this.paint.setStrokeCap(getAndroidCap(Cap.ROUND));
this.paint.setStrokeJoin(android.graphics.Paint.Join.ROUND);
this.paint.setStyle(getAndroidStyle(Style.FILL));
}
// in AwtCanvas.java:
AwtCanvas(Graphics2D graphics2D) {
this.graphics2D = graphics2D;
setAntiAlias(Parameters.ANTI_ALIASING);
createFilters();
}
public void setBitmap(Bitmap bitmap) {
if (bitmap == null) {
this.bufferedImage = null;
this.graphics2D = null;
} else {
this.bufferedImage = AwtGraphicFactory.getBitmap(bitmap);
this.graphics2D = this.bufferedImage.createGraphics();
setAntiAlias(Parameters.ANTI_ALIASING);
this.graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
this.graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}
}
有人知道吗,如何在Flutter / Dart中实现呢?文档(https://api.flutter.dev/flutter/dart-ui/Paint/isAntiAlias.html)中的方法似乎不适用于我。
谢谢!