'Converting photos from kivy camera to bytes. So I can send a photo using python sockets

I wanted to make a video-call app using kivy-python software. I ran into a problem: I wanted to send my photo, but they had type <class 'kivy.core.image.Image'> , but I needed byted. And I do not know how to serialize this object.

from kivy.app import App

from kivy.uix.camera import Camera

from kivy.uix.boxlayout import BoxLayout

from kivy.uix.button import Button


class CameraExample(App):

    def build(self):
        layout = BoxLayout(orientation='vertical')

        # Create a camera object

        self.cameraObject = Camera(play=False)

        self.cameraObject.play = True

        self.cameraObject.resolution = (300, 300)  # Specify the resolution

        # Create a button for taking photograph

        self.camaraClick = Button(text="Take Photo")

        self.camaraClick.size_hint = (.5, .2)

        self.camaraClick.pos_hint = {'x': .25, 'y': .75}

        # bind the button's on_press to onCameraClick

        self.camaraClick.bind(on_press=self.onCameraClick)

        # add camera and button to the layout

        layout.add_widget(self.cameraObject)

        layout.add_widget(self.camaraClick)
        return layout
        # return the root widget
    def onCameraClick(self, *args):
        self.cameraObject.export_to_png('selfie.png')
        #print(dir(self.cameraObject.export_as_image()))
        print(self.cameraObject.export_as_image())

Thank you in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source