Kivy-在Android上保存的截图[screenshot()]在哪里?

时间:2014-09-11 19:41:25

标签: android python python-2.7 kivy

我有一个很大的问题,当我在我的Android手机上使用screenshot()时,我不知道截图到底在哪里。我查了/ storage / emulated / 0 / Android / data但没有找到。我的应用程序甚至没有文件夹。

另外,有没有办法设置屏幕截图的保存位置?也许是一个更合乎逻辑的地方。

这是我的代码:`

from random import random
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.stacklayout import StackLayout
from kivy.clock import Clock
from kivy.uix.slider import Slider
from kivy.core.window import Window


thickness = 5

class MyPaintWidget(Widget):

    def on_touch_down(self, touch):
        color = (random(), 1, 1)
        with self.canvas:
            Color(*color, mode='hsv')
            touch.ud['line'] = Line(points=(touch.x, touch.y), width = thickness)

    def on_touch_move(self, touch):
        if 'line' in touch.ud:
            touch.ud['line'].points += [touch.x, touch.y]







class MyPaintApp(App):

    def build(self):
        #layouts
        w = Widget()
        b = BoxLayout()
        f = FloatLayout()
        a = AnchorLayout(anchor_x= 'left', anchor_y= 'bottom')
        s = StackLayout()
        #widgets
        p = MyPaintWidget()
        cb = Button(text='Clear')
        lb = Button(pos = (150,0), text = "Large\nBrush", halign = "center")
        mb = Button(pos = (300,0), text = "Medium\nBrush", halign = "center")
        sb = Button(pos = (450,0), text = "Small\nBrush", halign = "center")
        svb = Button(pos = (600, 0), text = "Save", halign = "center")

        #adding the widgets
        w.add_widget(p)
        w.add_widget(cb)
        w.add_widget(lb)
        w.add_widget(mb)
        w.add_widget(sb)
        w.add_widget(svb)
        #w.export_to_png('ScreenShot.png')



        #bindings
        def clear_canvas(obj):
            p.canvas.clear()
        cb.bind(on_release=clear_canvas)

        def large_brush(obj):
            global thickness
            thickness = 15
        lb.bind(on_release=large_brush)

        def medium_brush(obj):
            global thickness
            thickness = 10
        mb.bind(on_release=medium_brush)

        def small_brush(obj):
            global thickness
            thickness = 5
        sb.bind(on_release=small_brush)


        def Screenshot(obj):
            global Screenshotnum
            Window.screenshot(name="Screenshot.png")

        svb.bind(on_release=Screenshot)


        return w


if __name__ == '__main__':
   MyPaintApp().run()`

忽略“export_to_png”部分

2 个答案:

答案 0 :(得分:2)

屏幕截图保存到您指定的路径,在本例中只是当前目录中的文件名,可能位于/data/data中的某个位置,除非您具有root访问权限,否则其他应用程序无法访问该文件名。您可以使用os.getcwd()检查脚本中的目录。

您可以将要保存的外部存储文件路径作为screenshot的参数传递。一般情况下,您可以使用pyjnius查询android api以获取您建议应用程序应该使用的文件路径。

答案 1 :(得分:0)

您是否尝试过/ storage / emulated / 0 / Pictures / Screenshot