如何使用 ltk 显示图像?
我已经编写了读取 Windows 位图的代码,现在想用 ltk 显示它。 我怎样才能构造一个合适的对象? ltk有这样的功能吗? 如果不是,我怎样才能直接连接到 tk?
I have written code to read a windows bitmap and would now like to display it with ltk. How can I construct an appropriate object? Is there such functionality in ltk? If not how can I do it directly interfacing to tk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有使用 LTK 来做任何事情了,但使用 LTK 显示图像的最简单方法如下:
不幸的是,默认情况下您可以对图像执行的操作相当有限,并且只能使用 gif 或 ppm 图像 -但 ppm 文件格式 非常简单,您可以轻松地从位图创建 ppm 图像。 然而,您说您想要操作显示的图像,并查看定义图像对象的代码:
看起来图像的实际数据是由 Tcl/Tk 解释器存储的,并且无法从 lisp 中访问。 如果您想访问它,您可能需要使用 format-wish 和 send-wish 编写自己的函数。
当然,您可以简单地在画布对象上单独渲染每个像素,但我认为这样做不会获得很好的性能,一旦您尝试在画布上显示数千个不同的内容,画布小部件就会变得有点慢它。 总结一下 - 如果您不关心实时执行任何操作,则可以在每次想要显示位图时将其保存为 .ppm 图像,然后只需使用上面的代码加载它 - 这将是最简单的。 否则,您可以尝试从 tk 本身访问数据(将其作为 ppm 图像加载一次后),最后,如果这些都不起作用,您可以切换到另一个工具包。 大多数像样的 lisp GUI 工具包都是针对 Linux 的,所以如果你使用的是 Windows,你可能会运气不好。
It has been a while since I used LTK for anything, but the simplest way to display an image with LTK is as follows:
Unfortunately what you can do with the image by default is fairly limited, and you can only use gif or ppm images - but the ppm file format is very simple, you could easily create a ppm image from your bitmap. However you say you want to manipulate the displayed image, and looking at the code that defines the image object:
It looks like the the actual data for the image is stored by the Tcl/Tk interpreter and not accessible from within lisp. If you wanted to access it you would probably need to write your own functions using format-wish and send-wish.
Of course you could simply render each pixel individually on a canvas object, but I don't think you would get very good performance doing that, the canvas widget gets a bit slow once you are trying to display more than a few thousand different things on it. So to summarize - if you don't care about doing anything in real time, you could save your bitmap as a .ppm image every time you wanted to display it and then simply load it using the code above - that would be the easiest. Otherwise you could try to access the data from tk itself (after loading it once as a ppm image), finally if none of that works you could switch to another toolkit. Most of the decent lisp GUI toolkits are for linux, so you may be out of luck if you are using windows.
Tk 本身不支持 Windows 位图文件。 然而,“Img”扩展确实可以在几乎所有平台上免费使用。 您不需要读入数据,可以直接从磁盘上的文件创建图像。 在普通的 tcl/tk 中,您的代码可能如下所示:
可以在 http://wiki 找到更多信息.tcl.tk/6165
Tk does not natively support windows bitmap files. However, the "Img" extension does and is freely available on just about every platform. You do not need to read the data in, you can create the image straight from the file on disk. In plain tcl/tk your code might look something like this:
a little more information can be found at http://wiki.tcl.tk/6165