示例#1
0
def screenshot(path, root_widget=None):
    """
    Take screenshot of the current state of the app and save it under ``path``.

    The sleep- and mainthread-decorator ensure that the app shows the current state properly.
    """
    if root_widget is None:
        root_widget = MDApp.get_running_app().root

    fbo = Fbo(
        size=(root_widget.width, root_widget.height),
        with_stencilbuffer=True,
    )

    with fbo:
        ClearColor(*MDApp.get_running_app().theme_cls.bg_normal)
        ClearBuffers()
        Scale(1, -1, 1)
        Translate(-root_widget.x, -root_widget.y - root_widget.height, 0)

    fbo.add(root_widget.canvas)
    fbo.draw()
    img = KivyImage(fbo.texture)

    img.save(path)
示例#2
0
    def capture(self, event):
        if (self.camera.play):
            self.camera.play = False
            img = Image(self.camera.texture)
            img.save("capture.png")
            self.captureButton.text="Take another"
            self.classifyButton.disabled=False

        else:
            self.camera.play = True
            self.captureButton.text="Capture"
            self.classifyButton.disabled = True
 def _print_image(self, filename, *args, **kwargs):
     """Write out format png. The image is saved with the filename given.
     """
     l, b, w, h = self.figure.bbox.bounds
     img = None
     if self.img_texture is None:
         texture = Texture.create(size=(w, h))
         texture.blit_buffer(bytes(self.get_renderer().buffer_rgba()), colorfmt="rgba", bufferfmt="ubyte")
         texture.flip_vertical()
         img = Image(texture)
     else:
         img = Image(self.img_texture)
     img.save(filename)
示例#4
0
    def print_png(self, filename, *args, **kwargs):
        '''Call the widget function to make a png of the widget.
        '''
        fig = FigureCanvasAgg(self.figure)
        FigureCanvasAgg.draw(fig)

        l, b, w, h = self.figure.bbox.bounds
        texture = Texture.create(size=(w, h))
        texture.blit_buffer(bytes(fig.get_renderer().buffer_rgba()),
                                colorfmt='rgba', bufferfmt='ubyte')
        texture.flip_vertical()
        img = Image(texture)
        img.save(filename)
    def print_png(self, filename, *args, **kwargs):
        '''Call the widget function to make a png of the widget.
        '''
        fig = FigureCanvasAgg(self.figure)
        FigureCanvasAgg.draw(fig)

        l, b, w, h = self.figure.bbox.bounds
        texture = Texture.create(size=(w, h))
        texture.blit_buffer(bytes(fig.get_renderer().buffer_rgba()),
                                colorfmt='rgba', bufferfmt='ubyte')
        texture.flip_vertical()
        img = Image(texture)
        img.save(filename)
 def _print_image(self, filename, *args, **kwargs):
     '''Write out format png. The image is saved with the filename given.
     '''
     l, b, w, h = self.figure.bbox.bounds
     img = None
     if self.img_texture is None:
         texture = Texture.create(size=(w, h))
         texture.blit_buffer(bytes(self.get_renderer().buffer_rgba()),
                             colorfmt='rgba', bufferfmt='ubyte')
         texture.flip_vertical()
         img = Image(texture)
     else:
         img = Image(self.img_texture)
     img.save(filename)
示例#7
0
    def take_not_window_screenshot(self, shouldWholeWindowIfNone=False, *args):
        if globals.baseSysConfig.get("background_image", "see_through"):
            img = ImageGrab.grab()

            try:
                im = CoreImage(self.ids["ParentScreenImage"].texture)

            except Exception:
                Logger.warning(
                    globals.baseSysConfig.get("main", "parent_name") +
                    ": Window background image does not have a texture")

                if shouldWholeWindowIfNone:
                    self.minimize_screenshot()

                return

            data = BytesIO()
            im.save(data, fmt="png")
            data.seek(0)
            im = PILImage.open(data)

            wx, wy, ww, wh = CoreWindow.left, CoreWindow.top, CoreWindow.width, CoreWindow.height
            remAmount = globals.baseSysConfig.get("background_image",
                                                  "crop_distance")
            remAmountTop = globals.baseSysConfig.get("background_image",
                                                     "crop_distance_top")
            x, y, x2, y2 = wx - remAmount, wy - remAmountTop, wx + ww + remAmount, wy + wh + remAmount
            im = im.crop((x, y, x2, y2))

            img.paste(im, (x, y))

            data = BytesIO()
            img.save(data, format="png")
            data.seek(0)
            img = CoreImage(BytesIO(data.read()), ext='png')

            self.ids["ParentScreenImage"].texture = img.texture
示例#8
0
 def capture(self, event):
     print("catpured")
     self.tex = self.camera.texture
     img = Image(texture=self.tex)
     img.save("capture.png")
示例#9
0
    def read_stream(self):
        root = App.get_running_app().root
        
        try:
            stream = urlopen(self.url)
        except:
            self.stop(close_thread=False)
            return

        save_path = root.config.getdefault('stream', 'save_path', root.config_defaults['stream']['save_path'])

        if not os.path.exists(save_path):
            os.makedirs(save_path)

        if not os.path.isdir(save_path):  
            save_path = root.config_defaults['stream']['save_path']

        root.children[0].ids['take_picture_button'].opacity = 1
        self.opacity = 1

        self.is_save_image = False
        bytes = b''

        while self.is_alive:
            try:
                bytes += stream.read(5 * 1024)
            except:
                root.children[0].ids['take_picture_button'].opacity = 0
                self.stop(close_thread=False)
                return

            a = bytes.find(b'\xff\xd8')
            b = bytes.find(b'\xff\xd9')

            if a != -1 and b != -1:
                jpg = bytes[a:b + 2]
                bytes = bytes[b + 2:]

                data = io.BytesIO(jpg)
                data.seek(0)

                try:
                    im = CoreImage(data,
                                   ext='jpeg',
                                   nocache=True) 

                    if self.is_save_image:
                        self.is_save_image = False
                        date = datetime.datetime.now()
                        filename = date.strftime('%Y-%m-%d %H-%M-%S') + '.jpg'
                        full_path = os.path.join(save_path, filename)

                        
                        if os.path.exists(full_path):
                            i = 1
                            full_path = full_path[:-4] + f' ({i})' + '.jpg'

                            while os.path.exists(full_path):
                                full_path = full_path.replace(f'({i - 1})', f'({i})')
                                i += 1

                        im.save(full_path)                 
                except:
                    continue

                with self._image_lock:
                    self._image_buffer = im
示例#10
0
# carregar os dados da imagem diretamente de um bloco da memória
import io
from kivy.core.image import Image

data = io.BytesIO(open("image.png", "rb").read())
im = Image(data, ext="png")

# para imagem ficar salva em cache informe o filename
im = Image(data, ext="png", filename="image.png")

# Savar imagem
from kivy.core.image import Image

img = Image('hello.png')
img.save('hello2.png')

# salvar textura
texture = Texture.create(...)
img = Image(texture)
img.save('hello3.png')

# for example, load a 128x128 image that contain 4 64x64 images
from kivy.core.image import Image

texture = Image('mycombinedimage.png').texture
bottomleft = texture.get_region(0, 0, 64, 64)
bottomright = texture.get_region(0, 64, 64, 64)
topleft = texture.get_region(0, 64, 64, 64)
topright = texture.get_region(64, 64, 64, 64)
示例#11
0
 def capture(self, event):
     print("catpured")
     self.tex = self.camera.texture
     img = Image(texture=self.tex)
     img.save("capture.png")
示例#12
0
 def save_picture(self, picture):
     img = Image(picture)
     img.save('foto01.png')