无需枕头即可将PNG转换为JPEG

时间:2019-03-14 20:59:28

标签: android python kivy buildozer

如何在PNGJPEG)上没有Pillow的情况下将kivy文件转换为Python

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:2)

使用Kivy CoreImage从png转换为jpg。

摘要

from kivy.core.image import Image as CoreImage

img = CoreImage("linux.png")
img.save("linux.jpg")

示例

main.py

from kivy.uix.screenmanager import Screen
from kivy.core.image import Image as CoreImage
from kivy.lang import Builder
from kivy.base import runTouchApp

Builder.load_string('''
#:kivy 1.10.1

<Demo>:
    img_png: img_png
    img_jpg: img_jpg

    RelativeLayout:
        Image:
            id: img_png
            pos_hint: {"left": 1, 'bottom': 1}
            size_hint: 0.5, 1
            allow_stretch: True

    RelativeLayout:
        Image:
            id: img_jpg
            pos_hint: {"right": 1, 'bottom': 1}
            size_hint: 0.5, 1
            allow_stretch: True
''')


class Demo(Screen):

    def __init__(self, **kwargs):
        super(Demo, self).__init__(**kwargs)
        img = CoreImage("linux.png")
        img.save("linux.jpeg")
        self.img_png.source = "linux.png"
        self.img_jpg.source = "linux.jpeg"


runTouchApp(Demo())

输出

Converted image from png and jpeg