在没有 Pillow 的情况下将 PNG 转换为 JPEG
Convert PNG to JPEG without Pillow
如何在 kivy
(Python
) 上将 PNG
文件转换为 JPEG
而没有 Pillow
?
如有任何帮助,我们将不胜感激。谢谢!
使用 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())
输出
如何在 kivy
(Python
) 上将 PNG
文件转换为 JPEG
而没有 Pillow
?
如有任何帮助,我们将不胜感激。谢谢!
使用 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())