程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了图片顶部带有按钮的全屏 kivy 相机大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决图片顶部带有按钮的全屏 kivy 相机?

开发过程中遇到图片顶部带有按钮的全屏 kivy 相机的问题如何解决?下面主要结合日常开发的经验,给出你关于图片顶部带有按钮的全屏 kivy 相机的解决方法建议,希望对你解决图片顶部带有按钮的全屏 kivy 相机有所启发或帮助;

图片顶部带有按钮的全屏 kivy 相机

如何制作带有图像顶部按钮的全屏相机。

resolution: (self.wIDth,self.height)

这没有用,相机仍然带有框架。在官方文档中没有找到任何相关信息。

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_String('''
<CameraClick>:
    orIEntation: 'vertical'
    Camera:
        ID: camera
        resolution: (640,480)
        play: false
    Togglebutton:
        text: 'Play'
        on_press: camera.play = not camera.play
        size_hint_y: None
        height: '48dp'
    button:
        text: 'Capture'
        size_hint_y: None
        height: '48dp'
        on_press: root.capture()
''')


class CameraClick(BoxLayout):
    def capture(self):
        '''
        Function to capture the images and give them the names
        according to their captured time and date.
        '''
        camera = self.IDs['camera']
        timestr = time.strftime("%Y%m%d_%H%M%s")
        camera.export_to_png("img_{}.png".format(timestr))
        print("Captured")


class TESTCamera(App):

    def build(self):
        return CameraClick()


TESTCamera().run()

解决方法

对您的代码进行一些小的更改(组件重新排序,添加了 Window.maximize() 做我认为您正在寻找的东西(编辑:修改为使相机在静止时尽可能大) 保持纵横比)

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
import time

Window.maximize()

Builder.load_String(
    '''
<CameraClick>:
    orientation: 'vertical'
    ToggleButton:
        text: 'Play'
        on_press: camera.play = not camera.play
        size_hint_y: None
        height: '48dp'
    Button:
        text: 'Capture'
        size_hint_y: None
        height: '48dp'
        on_press: root.capture()
    Camera:
        id: camera
        resolution: (640,480)
        allow_stretch: True
        keep_ratio: True
        play: false
'''
)


class CameraClick(BoxLayout):
    def capture(self):
        '''
        Function to capture the images and give them the names
        according to their captured time and date.
        '''
        camera = self.ids['camera']
        timestr = time.strftime("%Y%m%d_%H%M%S")
        camera.export_to_png("IMG_{}.png".format(timestr))
        print("Captured")


class TESTCamera(App):

    def build(self):
        return CameraClick()


TESTCamera().run()

大佬总结

以上是大佬教程为你收集整理的图片顶部带有按钮的全屏 kivy 相机全部内容,希望文章能够帮你解决图片顶部带有按钮的全屏 kivy 相机所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。