0

I am writing code on my Android. I know, it's weird. But my notebook is being repaired :)

I am trying to display an image generated by pillow library. I'm doing this within Pydroid app.

Matplotlib charts are displaying okay. But not the image of pillow.

There is a question similar to mine, that links this problem to image magic not being installed. But it is not particular to Android. If this is also the case for me, please specify how to install it, since it is not a pip package. Here is my code

    from PIL import Image

    img = Image.new(
        mode='RGB',
        size=(400, 240),
        color=(153,153,153)
    )
    img.show()
Lex Podgorny
  • 2,598
  • 1
  • 23
  • 40

1 Answers1

1

The PIL.IMage.show() method is really just a quick debugging tool that uses your OS's built-in image viewer (IMageMagick display, eog or xv on Linux, Preview on macOS) to quickly view a PIL Image. I don't think anyone anticipated its use on Android.

I am unfamiliar with Android, but if you know of an image viewer for that platform you can maybe integrate it like this.

If not, as it's just a quick debugging tool, and as Matplotlib works, you can use that to display your PIL Images:

from PIL import Image
import matplotlib.pyplot as plt

# Create a PIL Image
img = Image.new('RGB', (400, 240), color=(255,0,0))

# Display with Matplotlib
plt.imshow(img)
plt.axis('off')
plt.show()
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432