How can I make a full screen camera with buttons on top of the image.
JavaScript
x
2
1
resolution: (self.width, self.height)
2
It doesn’t help, the camera still comes out with frames. Didn’t find anything about this in the official documentation.
JavaScript
1
44
44
1
from kivy.app import App
2
from kivy.lang import Builder
3
from kivy.uix.boxlayout import BoxLayout
4
import time
5
Builder.load_string('''
6
<CameraClick>:
7
orientation: 'vertical'
8
Camera:
9
id: camera
10
resolution: (640, 480)
11
play: False
12
ToggleButton:
13
text: 'Play'
14
on_press: camera.play = not camera.play
15
size_hint_y: None
16
height: '48dp'
17
Button:
18
text: 'Capture'
19
size_hint_y: None
20
height: '48dp'
21
on_press: root.capture()
22
''')
23
24
25
class CameraClick(BoxLayout):
26
def capture(self):
27
'''
28
Function to capture the images and give them the names
29
according to their captured time and date.
30
'''
31
camera = self.ids['camera']
32
timestr = time.strftime("%Y%m%d_%H%M%S")
33
camera.export_to_png("IMG_{}.png".format(timestr))
34
print("Captured")
35
36
37
class TestCamera(App):
38
39
def build(self):
40
return CameraClick()
41
42
43
TestCamera().run()
44
Advertisement
Answer
Some minor changes to your code (component reorder, added Window.maximize()
do what I think you’re looking for (edit: modified to make the camera as large as possible while still
maintaining aspect ratio)
JavaScript
1
52
52
1
from kivy.app import App
2
from kivy.lang import Builder
3
from kivy.uix.boxlayout import BoxLayout
4
from kivy.core.window import Window
5
import time
6
7
Window.maximize()
8
9
Builder.load_string(
10
'''
11
<CameraClick>:
12
orientation: 'vertical'
13
ToggleButton:
14
text: 'Play'
15
on_press: camera.play = not camera.play
16
size_hint_y: None
17
height: '48dp'
18
Button:
19
text: 'Capture'
20
size_hint_y: None
21
height: '48dp'
22
on_press: root.capture()
23
Camera:
24
id: camera
25
resolution: (640, 480)
26
allow_stretch: True
27
keep_ratio: True
28
play: False
29
'''
30
)
31
32
33
class CameraClick(BoxLayout):
34
def capture(self):
35
'''
36
Function to capture the images and give them the names
37
according to their captured time and date.
38
'''
39
camera = self.ids['camera']
40
timestr = time.strftime("%Y%m%d_%H%M%S")
41
camera.export_to_png("IMG_{}.png".format(timestr))
42
print("Captured")
43
44
45
class TestCamera(App):
46
47
def build(self):
48
return CameraClick()
49
50
51
TestCamera().run()
52