[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Drawing in images?
From: |
YAMAMOTO Mitsuharu |
Subject: |
Re: Drawing in images? |
Date: |
Fri, 28 Aug 2009 09:49:58 +0900 |
User-agent: |
Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) |
>>>>> On Wed, 26 Aug 2009 00:57:17 +0200, address@hidden said:
> I would like to draw a bounding box inside an image displayed in
> emacs. Do I:
> a) use clever already existing way, unknown to me
Maybe existing image slicing and box drawing with face can be used for
some simple cases.
(defface inner-box '((t :box (:line-width -1))) "Simple box")
(defun insert-image-with-box (image x y w h)
(let* ((image-size (image-size image t))
(image-width (car image-size))
(image-height (cdr image-size)))
(if (or (<= w 0) (<= h 0) (< x 0) (< y 0)
(> (+ x w) image-width) (> (+ y h) image-height))
(error "Box empty or not contained in the image")
(when (> y 0)
(insert-image image nil nil (list 0 0 image-width y))
(insert (propertize "\n" 'line-height t)))
(when (> x 0)
(insert-image image nil nil (list 0 y x h)))
(insert (propertize " " 'display `((slice ,x ,y ,w ,h) ,image)
'face 'inner-box))
(when (< (+ x w) image-width)
(insert-image image nil nil (list (+ x w) y (- image-width x w) h)))
(insert (propertize "\n" 'line-height t))
(when (< (+ y h) image-height)
(insert-image image nil nil (list 0 (+ y h)
image-width (- image-height y h)))
(insert (propertize "\n" 'line-height t))))))
;; Turn off font-lock-mode before you try this in *scratch*.
(insert-image-with-box (create-image "splash.png") 50 30 100 150)
YAMAMOTO Mitsuharu
address@hidden