Kivy-在Android上将窗口导出为png [英] Kivy--Export Window as png on Android

查看:81
本文介绍了Kivy-在Android上将窗口导出为png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android上创建一个应用,其中您要填充几个TextInputs,然后在剩下的标记空间上给您签名,我有2个按钮,一个用于清除,一个用于将窗口导出为png ,但是当我将其构建为.apk并将其在平板电脑上运行时,一切仍然看起来不错,并且按导出按钮不会出现错误,但是我找不到自己的照片,有人说要在代码所在的目录,但就我而言,它是一个应用程序(.apk),我将添加代码,即使我认为它与问题无关.

I am trying to create a app on android with wich you fill in a few TextInputs and then give your signature on a marked space left for that, I have 2 buttons, one for clearing and one for exporting the window as a png, however when I buildozer this as a .apk and then run it on my Tablet everything still looks fine, and pressing the exporting button dont give a error, but I cant find a image for the life of me, someone said to look in the directory the code is in, but in my case its a app (.apk), I'll add my code, even though i dont think it has much to do with the problem.

非常感谢您的帮助

__version__ = "0.2"
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
from kivy.core.window import Window
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.config import Config
from kivy.base import EventLoop


class MyPaintWidget(Widget):
    Window.clearcolor = (0.95, 0.95, 0.85, 1)

    def on_touch_down(self, touch):
        color = (0,0,0)
        with self.canvas:
            Color(*color, mode='hsv')
            d = 3
            Ellipse(pos=(touch.x - d / 2, (touch.y - d / 2)+50), size=(d, d))
            touch.ud['line'] = Line(points=(touch.x, touch.y+50),width=1.5)

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


class WaentjiesApp(App):
    display_width = 1200
    global parent
    def build(self):
        global parent
        Window.size = (self.display_width, 500)
        parent = FloatLayout()
        self.painter = MyPaintWidget()
        save_button = Button(text = 'Save',pos=(0,0),size_hint=(.20,.20),on_release=self.save_canvas)
        clear_button = Button(text = 'Clear',pos=(300,0),size_hint=(.20,.20),on_release=self.clear_canvas)
        name_text = TextInput(text='',pos=(0,370),size_hint=(.15,.15))
        van_text = TextInput(text='',pos=(200,370),size_hint=(.15,.15))
        adres_text = TextInput(text='',pos=(0,220),size_hint=(.15,.15))
        waentjie_text = TextInput(text='',pos=(200,220),size_hint=(.15,.15))
        name_label = Label(text='Naam',pos=(0,450),size_hint=(.15,.15),color=(0,0,0,1))
        van_label = Label(text='Van',pos=(200,450),size_hint=(.15,.15),color=(0,0,0,1))
        adres_label = Label(text='Adres',pos=(0,300),size_hint=(.15,.15),color=(0,0,0,1))
        waentjie_label = Label(text='Waentjie',pos=(200,300),size_hint=(.15,.15),color=(0,0,0,1))
        handtekening1_label = Label(text='Handtekening',pos=(400,350),size_hint=(.15,.15),color=(0,0,0,1))
        handtekening2_label = Label(text='......................................................................................................................................',pos=(600,190),size_hint=(.15,.15),color=(0,0,0,0.5))
        agtergrond = Label()
        parent.add_widget(handtekening2_label)
        parent.add_widget(self.painter)
        parent.add_widget(save_button)
        parent.add_widget(clear_button)
        parent.add_widget(name_text)
        parent.add_widget(van_text)
        parent.add_widget(adres_text)
        parent.add_widget(name_label)
        parent.add_widget(van_label)
        parent.add_widget(adres_label)
        parent.add_widget(waentjie_text)
        parent.add_widget(waentjie_label)
        parent.add_widget(handtekening1_label)
        return parent

    def save_canvas(self, obj):
        global parent
        parent.export_to_png('b.png')

    def clear_canvas(self, obj):
        self.painter.canvas.clear()


WaentjiesApp().run()

一些变量和名称可能看起来很奇怪,但是英语不是我的母语,所以我倾向于选择其他语言的名称

some of the variables and names might seem weird, but english is not my first language so I tend to choose other-langage names

推荐答案

文件保存在当前目录中,您可以使用例如脚本中的os.path.realpath('.').其他应用程序无法访问此目录.如果要从其他应用程序访问文件,请将其保存在外部存储目录中的某个位置(使用Kivy,可以使用App.user_data_dir).

The file is saved in the current directory, which you can access with e.g. os.path.realpath('.') from your script. This directory is not accessible to other applications. If you want to access the file from other applications, save it somewhere in the external storage dir (with Kivy, you can use App.user_data_dir).

这篇关于Kivy-在Android上将窗口导出为png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆