Où sommes nous ?


Image viewer

Only an example to show how to display à JPEG image, simplied version of DirectFB's own tutorial.

Classical shebang to use Séléné as script interpretor. Obviously, the path has to be changed as per your own installation.


Tell to Séléné we want to use DirectFB and pass some option to it :


We want whole screen and then we get its primary surface.
Finally, clear it and get its size.

DirectFB.init( DirectFB.CooperativeConst('FULLSCREEN') )
srf = SelSurface.create { caps=SelSurface.CapabilityConst('PRIMARY') }
w,h = srf:GetSize()

Load the image as ... an image provider and handle potential error (obviously, the path has to be changed as per the actual image location).

local img,err = SelImage.create("/root/trv/DirectFB-examples-1.2.0/data/wood_andi.jpg")
if not img then
error("Can't load image")

Create our primary surface, clear it and retreive its size

local srf = SelSurface.create {
srf:Clear( 0,0,0,0 )
local w,h = srf:GetSize()

Render to the created surface.

   { 20, 20, w-40, h-40 } -- Conform to surface size, w/ 20px margins

with :

We don't need the orignal image anymore, releasing it


Normally, we have now to refresh the display, but it's implicit here and we have only to wait for user's input.

print "Hit 'enter' key to exit"

It's over : time to do usual cleaning. It's not mandatory as Séléné takes it on his own if not explicitly made.


The full source code is here.

The image can now be manipulated as other surface : drawing, blitting ... So it a very convenient way to create fancy GUI by working directly on the background image and then add dynamically objects handled by Séléné ... it's what I'm doing for my dashboards.

Visitez :
La liste de nos voyages
Nos sorties Ski et rando
Copyright Laurent Faillie 2001-2017
N'oubliez pas d'entrer le mot de passe pour voir aussi les photos perso.
Contactez moi si vous souhaitez réutiliser ces photos et pour les obtenir avec une plus grande résolution.
Visites durant les 7 derniers jours Nombre de visites au total.

Vous pouvez laissez un commentaire sur cette page.