从 Blackberry 上的 BrowserField 获取图形对象或位图

发布于 2024-12-06 01:23:40 字数 81 浏览 0 评论 0原文

我想获取浏览器字段中显示的网页内容的位图。因此我需要浏览器字段的图形对象。但不幸的是,油漆方法受到了保护。 有办法得到这个吗?

谢谢

I would like to get the Bitmap of the content of a webpage as it is displayed in the BrowserField. Therefore I'd need the Graphic-object of the browser field. But the paint-method is protected unfortunately.
Is there a way to get this?

Thank's

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

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

发布评论

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

评论(1

不再见 2024-12-13 01:23:40

通常,如果您想使用字段进行一些自定义绘图,即。绘制到字段的图形上下文中,您需要子类化 Field 并重写 paint 方法。但是,当涉及到 BrowserField 时,您不能这样做,因为它被声明为最终的。

不过,有一个解决方法。您可以对 Manager 进行子类化,并将 BrowserField 添加到该管理器的实例中。因此,例如,如果要将 BrowserField 实例添加到 VerticalFieldManager,则可以使用以下代码来访问浏览器将绘制到的 Graphics 对象。在此示例代码中,您将看到我使用图形对象和管理器的超类实现来绘制位图。然后,该位图被绘制到屏幕上。

VerticalFieldManager vfm = new VerticalFieldManager() {
    // Override to gain access to Field's drawing surface
    //
    protected void paint(Graphics graphics) {

        // Create a bitmap to draw into 
        //
        Bitmap b = new Bitmap(vfm.getVirtualWidth(), vfm.getVirtualHeight());

        // Create a graphics context to draw into the bitmap
        //
        Graphics g = Graphics.create(b);

        // Give this graphics context to the superclass implementation
        // so it will draw into the bitmap instead of the screen
        //
        super.paint(g);

        // Now, draw the bitmap
        //
        graphics.drawBitmap(0, 
                0, 
                vfm.getVirtualWidth(), 
                vfm.getVirtualHeight(), 
                b, 
                0, 
                0);

    }
};

并且,您有一个包含管理器内容的位图。但应该注意,这可能会消耗大量内存。

Normally, if you want to do some custom drawing with a field ie. draw into the field's graphics context, you'd subclass Field and override the paint method. However, when it comes to BrowserField, you can't do that because it's declared final.

There is a workaround for this, though. You can subclass a Manager and add your BrowserField to an instance of that manager. So, for example, if you want to add your BrowserField instance to a VerticalFieldManager, you can use the following code to get access to the Graphics object the browser will be drawn into. In this sample code, you'll see that I use the graphics object and manager's superclass implementation to draw into a bitmap. Then, that bitmap is drawn to the screen.

VerticalFieldManager vfm = new VerticalFieldManager() {
    // Override to gain access to Field's drawing surface
    //
    protected void paint(Graphics graphics) {

        // Create a bitmap to draw into 
        //
        Bitmap b = new Bitmap(vfm.getVirtualWidth(), vfm.getVirtualHeight());

        // Create a graphics context to draw into the bitmap
        //
        Graphics g = Graphics.create(b);

        // Give this graphics context to the superclass implementation
        // so it will draw into the bitmap instead of the screen
        //
        super.paint(g);

        // Now, draw the bitmap
        //
        graphics.drawBitmap(0, 
                0, 
                vfm.getVirtualWidth(), 
                vfm.getVirtualHeight(), 
                b, 
                0, 
                0);

    }
};

And, there you have a Bitmap containing the contents of the manager. Should note, though, that this has the potential to consume a lot of memory.

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