从 Blackberry 上的 BrowserField 获取图形对象或位图
我想获取浏览器字段中显示的网页内容的位图。因此我需要浏览器字段的图形对象。但不幸的是,油漆方法受到了保护。 有办法得到这个吗?
谢谢
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,如果您想使用字段进行一些自定义绘图,即。绘制到字段的图形上下文中,您需要子类化 Field 并重写 paint 方法。但是,当涉及到 BrowserField 时,您不能这样做,因为它被声明为最终的。
不过,有一个解决方法。您可以对 Manager 进行子类化,并将 BrowserField 添加到该管理器的实例中。因此,例如,如果要将 BrowserField 实例添加到 VerticalFieldManager,则可以使用以下代码来访问浏览器将绘制到的 Graphics 对象。在此示例代码中,您将看到我使用图形对象和管理器的超类实现来绘制位图。然后,该位图被绘制到屏幕上。
并且,您有一个包含管理器内容的位图。但应该注意,这可能会消耗大量内存。
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.
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.