Some time has passed since I used LTK for something, but the easiest way to display an image using LTK is as follows:
(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)))))
Unfortunately, what you can do with the default image is pretty limited, and you can only use gif or ppm images, but the ppm file format is very simple, you can easily create a ppm image from your bitmap. However, you say that you want to manipulate the displayed image and are looking at the code that defines the image object:
(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 ~A~@ [ -width ~a~] ~@ [ -height ~a~] ~@ [ -format \"~a\"~] ~@ [ -grayscale~*~] ~@ [ -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)
It seems that the actual data for the image is stored by the Tcl / Tk interpreter and is not accessible from lisp. If you want to access it, you probably have to write your own functions using the wish- and- send-wish format .
Of course, you can simply render each pixel separately on the canvas object, but I donβt think you will get very good performance, as the widget gets a little slow when you try to display more than several thousand different things on it. So, to summarize - if you don't need to do anything in real time, you can save the bitmap as a .ppm image every time you want to display it, and then just load it using the code above - that would be the easiest . Otherwise, you can try to access data from tk itself (after downloading it once as a ppm image), finally, if none of these actions work, you can switch to another set of tools. Most decent lisp GUIs for Linux, so you might be out of luck if you use windows.
source share