Salut,

Je programme du OpenGL sous Python et j'ai besoin d'ouvrir une image et de la passer dans un string.
J'utilise donc les 2 fonctions suivantes :

Image.open(infile) => image

im.tostring() => string
Returns a string containing pixel data, using the standard "raw" encoder.

im.tostring(encoder, parameters) => string
Returns a string containing pixel data, using the given data encoding.
Pour ce qui est d'ouvrir le fichier il n'y a pas trop de problème par contre je ne sais pas trop quels paramètres passer à la fonction tostring pour une image couleur bitmap (.bmp).

J'ai déjà fait qq test comme le suivant qui marche pour une image monochrome bitmap (.bmp)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
image = image.tostring('raw', 'L', 0, -1)
Or pour mon image couleur ce code me renvoir l'erreur suivante

Traceback (most recent call last):
File "x.py", line 1022, in DisplayGLScene
subDisplay()
File "x.py", line 1055, in subDisplay
ImageSF('atomes_ID', [1-tmp,0.5], 20.0)
File "x.py", line 299, in ImageSF
LoadAlphaTexture(os.path.abspath(os.path.curdir)+"\\"+img+".bmp" )
File "x.py", line 236, in LoadAlphaTexture
image = image.tostring('raw', 'L', 0, -1)
File "C:\Python23\Lib\site-packages\PIL\Image.py", line 439, in tostring
e = _getencoder(self.mode, encoder_name, args)
File "C:\Python23\Lib\site-packages\PIL\Image.py", line 323, in _getencoder
return apply(encoder, (mode,) + args + extra)
SystemError: unknown raw mode
Si vous pouvez me renseigner sur cette fonction.

Merci