我已经编写了读取Windows位图的代码,现在想用ltk显示它。我怎样才能构建一个合适的对象? ltk中是否有这样的功能?如果不是,我怎么能直接连接到tk呢?如何用ltk显示图像?
4
A
回答
3
发现它已经有一段时间,因为我用LTK任何东西,但最简单的方法显示与LTK的图像如下:
(defpackage #:ltk-image-example
(:use #:cl #:ltk))
(in-package #:ltk-image-example)
(defun image-example()
(with-ltk()
(let ((image (make-image)))
(image-load image "testimage.gif")
(let ((canvas (make-instance 'canvas)))
(create-image canvas 0 0 :image image)
(configure canvas :width 800)
(configure canvas :height 640)
(pack canvas)))))
不幸的是,你可以使用默认的图像做的是相当有限的,你只能使用GIF或ppm图像 - 但是很简单的,你可以很容易从中创建一个ppm图像你的位图。但是你说你要操纵所显示的图像,并期待在定义图像对象的代码:
(defclass photo-image(tkobject)
((data :accessor data :initform nil :initarg :data)
)
)
(defmethod widget-path ((photo photo-image))
(name photo))
(defmethod initialize-instance :after ((p photo-image)
&key width height format grayscale data)
(check-type data (or null string))
(setf (name p) (create-name))
(format-wish "image create photo [email protected][ -width ~a~][email protected][ -height ~a~][email protected][ -format \"~a\"~][email protected][ -grayscale~*~][email protected][ -data ~s~]"
(name p) width height format grayscale data))
(defun make-image()
(let* ((name (create-name))
(i (make-instance 'photo-image :name name)))
;(create i)
i))
(defgeneric image-load (p filename))
(defmethod image-load((p photo-image) filename)
;(format t "loading file ~a~&" filename)
(send-wish (format nil "~A read {~A} -shrink" (name p) filename))
p)
它看起来像该图像的实际数据被Tcl/Tk解释和无法访问存储从lisp内部。如果你想访问它,你可能需要使用format-wish和send-wish来编写自己的函数。
当然,您可以简单地在画布对象上单独渲染每个像素,但我不认为这样做会获得非常好的性能,一旦尝试显示更多的画布,画布窗口部件会变得有点慢上千种不同的东西。所以总结一下 - 如果你不关心实时做什么,你可以将你的位图保存为.ppm图像,每次你想显示它,然后使用上面的代码加载它 - 这将是最简单的。否则,您可以尝试从tk本身访问数据(在将其作为ppm图像加载一次之后),最后如果没有任何作用,您可以切换到另一个工具包。大部分像样的lisp GUI工具包都是针对linux的,所以如果你使用的是windows,你可能会失败。
2
Tk本身不支持Windows位图文件。但是,“Img”扩展可以在几乎每个平台上自由使用。您不需要读取数据,您可以直接从磁盘上的文件创建映像。在普通的Tcl/Tk您的代码可能是这个样子:
package require Img
set image [image create photo -file /path/to/image.bmp]
label .l -image $image
pack .l
一点的更多信息可以在http://wiki.tcl.tk/6165
相关问题
- 1. 显示标签:如何使用显示标签显示图像
- 2. 如何显示该图像?
- 3. 图像如何显示?
- 4. express.js如何显示图像?
- 5. Skimage:如何显示图像
- 6. WEBGL - 如何显示图像?
- 7. 如何显示在图像
- 8. 如何显示图像
- 9. 如何显示图像Codeigniter
- 10. 如何显示图像?
- 11. 我如何显示图像?
- 12. SimpleCursorAdapter如何显示图像?
- 13. 使图像显示...如何?
- 14. 如何在内容没有图像时显示图像并在显示图像时显示图像
- 15. 如何使用向导显示图像
- 16. 如何使用Javascript显示图像?
- 17. 如何使用XML显示图像?
- 18. 如何使用php显示图像?
- 19. 如何使用kivy显示图像
- 20. 如何使用c显示图像?
- 21. 如何使用Xcode显示图像
- 22. 如何使用MVC 4显示图像?
- 23. 如何用pygame显示PIL图像?
- 24. 如何用php显示图像?
- 25. 如何使用web.py显示图像
- 26. 如何使用WebView来显示图像
- 27. 如何用Perl显示图像
- 28. 如何使用函数显示图像?
- 29. 如何使用OpenCV显示PGM图像
- 30. 如何使用typeahead.js显示图像?
在这种情况下,我的问题是:如何获得数据?我想申请一些图像过滤器。 – Sarien 2008-09-17 08:13:08