简体   繁体   中英

Convert PNG to JPEG without Pillow

How can I convert a PNG file to JPEG without Pillow on kivy ( Python )?

Any help will be appreciated. Thank you!

Use Kivy CoreImage to convert from png to jpg.

Snippets

from kivy.core.image import Image as CoreImage

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

Example

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())

Output

从png和jpeg转换的图像

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM