I want to display Album Art that is stored in a tag from a Python program. I can access the SDBImage object and extract the image dimensions etc but so far none of my attempts to use the ImageData value to create an image have worked. My current code is as follows:
Code: Select all
print("Image format:", img.ImageFormat, "Size: ", img.Width, " x ", img.Height, " Length: ", img.ImageDataLen)
iw = img.Width
ih = img.Height
p = ctypes.cast(img.ImageData, ctypes.c_char_p)
im = PIL.Image.frombytes("RGB", (iw, ih), p, "jpeg", "RGB", None, 1)
im = im.resize((256, 256))
self.albumimage = PIL.ImageTk.PhotoImage(im)
self.imgcanvas.create_image(128, 128, image=self.albumimage, anchor=tk.CENTER)
self.imgcanvas.update()
"Image format: image/jpeg Size: 500 x 492 Length: 43667"
then throws the error:
"ValueError: cannot decode image data"
If I create the PhotoImage from a file saved from the same album the image is displayed correctly.
I have studied the information http://www.mediamonkey.com/wiki/index.p ... :ImageData which gives an example in VB and have also read the topic http://www.mediamonkey.com/forum/viewto ... ta#p376271
The latter suggests writing the data to an intermediate file, however I cannot work out how to do this in Python either.
Could someone post an example please of how one might do this in Python 3
Many thanks