【问题标题】:how to import python PIL on android and kivy?如何在 android 和 kivy 上导入 python PIL?
【发布时间】:2016-07-24 23:06:46
【问题描述】:

我想创建一个应用程序,从相机拍摄照片并在 android 上显示它们的缩略图。我的代码的相关部分是:

from plyer import camera
from PIL import Image
.
.
.
    def take_photo_from_camera(self, x):
        filename = str(random.randint(0, 100000000000)) # create random filenames
        self.camera.take_picture("/storage/sdcard0/MyApp/%s.jpg"%(filename), self.on_success_shot)


    def on_success_shot(self, path):
        #Create a thumbnail of taken photo here using PIL

我可以毫无问题地使用安卓相机。 我已将 PIL/pillow 添加到 kivy buildozer.spec 文件的要求中

requirements = kivy, openssl, futures, requests, plyer, pyjnius, pillow

当我想使用此配置创建 apk 时,apk 包会成功构建,但如果我安装 apk 并在我的 android 手机上运行,​​我会在 logcat 中收到此错误:

I/python  (20188):  Traceback (most recent call last):
I/python  (20188):    File "/home/mnrl/teknik/.buildozer/android/app/main.py", line 32, in <module>
I/python  (20188):    File "/home/mnrl/teknik/.buildozer/android/app/_applibs/PIL/Image.py", line 67, in <module>
I/python  (20188):  ImportError: dlopen failed: "/data/data/org.tokerteknik.tokerteknik/files/_applibs/PIL/_imaging.so" is 64-bit instead of 32-bit
I/python  (20188): Python for android ended.

我认为这个问题与架构有关。我正在使用 ubuntu 16.04 64 位和 kivy buildozer 在安装要求时使用 pip 安装 64 位库。 这里也有类似的问题:https://github.com/kivy/kivy/issues/4095 但没有任何解决方案。 简而言之,如何使用 kivy buildozer 在 android 上导入 PIL 或如何在 64 位系统上安装 PIL 的 32 位库?

【问题讨论】:

  • 这可能是python-for-android中的一个错误,你能在python-for-android github page上打开一个问题,同时报告完整的构建日志吗?
  • @inclement 是的,我已将此错误报告给 python for android github 页面。我将使用 pygame 而不是 pil 来调整图像大小,它对我有用,谢谢:)

标签: android python python-imaging-library kivy


【解决方案1】:

使用 pygame 而不是 PIL 进行基本的图像处理过程。 将 pygame 添加到 buildozer 需求列表中,它可以正常工作。

import pygame
picture = pygame.image.load(filepath)
picture = pygame.transform.scale(picture, (100, 100))
pygame.image.save(picture, "scaled_image.png")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2018-09-17
    • 1970-01-01
    相关资源
    最近更新 更多