mercredi 19 avril 2017

How to use the draw function

How to use the draw function

In the previous examples, we used the draw facet of a face to apply geometrical transformations on image such as translations or rotations. But draw also designs a powerful Red function that can be used to modify the content of an image. Any Red image can be passed as parameter to the draw function. 

The idea is simple. First copy into a block the modifications you want apply to the image as a list of draw operations.

plot: copy [line-width 2 pen red line 0x0 512x512 pen off pen green line 0x512 512x0 box 10x10 50x50 box 55x55 75X75 text 210x5 "Hello Lena"]

Then ask the image container to draw the image and the modifications you defined.

canvas/image: draw img plot


Code example



Red [
    Title:   "Draw tests "
    Author:  "Francois Jouen"
    File:    %DrawOnImage.red
    Needs:   'View
]

;How to use the draw function and not draw facet!

img: load %lena.jpg
margins: 5x5

plot: copy [line-width 2 pen red line 0x0 512x512 pen off pen green line 0x512 512x0  box 10x10 50x50 box 55x55 75X75 text 210x5 "Hello Lena"
]


view win: layout [
        title "Image Tests"
        origin margins space margins
        button 60 "Draw"    [canvas/image: draw img plot]
        button 60 "Quit"    [Quit]
        return 
        canvas: base 512x512 img
        return
        sbar: field 250
        do [sbar/data: length? img/rgb]
]

and the result




Aucun commentaire:

Enregistrer un commentaire