为什么 Android 地图指南针演示使用 SmoothCanvas 类的委托?

发布于 2024-09-11 10:15:49 字数 549 浏览 6 评论 0原文

在 Eclipse 中针对 Google API 提供的 Android MapsDemo 中,他们在 MapViewCompassDemo.java 中创建了一个内部类 SmoothCanvas。在此类中,重新实现了几乎所有方法,并将其重新路由到 Canvas 的委托实例。

static final class SmoothCanvas extends Canvas {
    Canvas delegate;

    private final Paint mSmooth = new Paint(Paint.FILTER_BITMAP_FLAG);

    public void setBitmap(Bitmap bitmap) {
        delegate.setBitmap(bitmap);
    }

    public void setViewport(int width, int height) {
        delegate.setViewport(width, height);
    }
    ...

在这种情况下,委托的意义何在?

In the Android MapsDemo available in Eclipse for the Google API, they create an inner class SmoothCanvas in MapViewCompassDemo.java. Within this class the re-implement seemingly every method and reroute it to a delegate instance of Canvas.

static final class SmoothCanvas extends Canvas {
    Canvas delegate;

    private final Paint mSmooth = new Paint(Paint.FILTER_BITMAP_FLAG);

    public void setBitmap(Bitmap bitmap) {
        delegate.setBitmap(bitmap);
    }

    public void setViewport(int width, int height) {
        delegate.setViewport(width, height);
    }
    ...

What is the point of the delegate in this instance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑饮青盏花 2024-09-18 10:15:49

delegate 的值被传递给 dispatchDrawSmoothCanvas 类是 delegate 的包装器。通过委托,传递给 dispatchDrawCanvas 实现会完成所有繁重的工作。包装器只允许注入平滑的油漆,而不实现 Canvas 的所有逻辑。

The value of delegate is passed in to dispatchDraw. The SmoothCanvas class is a wrapper around delegate. By delegating, the Canvas implementation passed to dispatchDraw does all the heavy lifting. The wrapper just allows the injection of the smoothed paint without implementing all the logic of Canvas.

余生一个溪 2024-09-18 10:15:49

在这种情况下委托的关键点是:

private final Paint mSmooth = new Paint(Paint.FILTER_BITMAP_FLAG);

<块引用>

FILTER_BITMAP_FLAG< /a> 位。过滤会影响位图转换时的采样。过滤不会影响位图中的颜色转换为设备像素的方式。这取决于抖动和 xfermode。



通过激活该标志,绘制位图基本上会提高其性能。在示例中,您将在每个 drawBitmap 调用中使用 mSmoth

The key point of delegating in that instance is:

private final Paint mSmooth = new Paint(Paint.FILTER_BITMAP_FLAG);

FILTER_BITMAP_FLAG bit. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.

By activating that flag, drawing bitmaps will basically increase its performance. You will in the example that mSmoth is used in every drawBitmap call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文