[Python/PIL] Librairie Image

Librairie Image [Python/PIL] - Python - Programmation

Marsh Posté le 13-04-2006 à 10:06:03    

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 :
 

Citation :

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)
 

Citation :

image = image.tostring('raw', 'L', 0, -1)


Or pour mon image couleur ce code me renvoir l'erreur suivante
 

Citation :

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

Reply

Marsh Posté le 13-04-2006 à 10:06:03   

Reply

Marsh Posté le 22-04-2006 à 21:10:11    

Pourquoi tu ne l'utilises pas sans lui fournir de paramètres?
 
J'ai testé avec un JPEG en couleur, tostring() fonctionne nickel [:spamafote]


Message édité par masklinn le 22-04-2006 à 21:13:43

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 26-04-2006 à 10:46:39    

J'ai réussi à me débloquer de ce problème et en effet j'utilise la fonction sans paramètre. J'arrive donc à charger des .bmp avec la fonction.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed