(self, png_filename=None, format='pillow')
Screenshot with PNG format

        Args:
            png_filename(string): optional, save file name
            format(string): return format, "raw" or "pillow” (default)

        Returns:
            PIL.Image or raw png data

        Raises:
            WDARequestError
Screenshot with PNG format
Screenshot with PNG format
def screenshot(self, png_filename=None, format='pillow'):
        """
        Screenshot with PNG format

        Args:
            png_filename(string): optional, save file name
            format(string): return format, "raw" or "pillow” (default)

        Returns:
            PIL.Image or raw png data

        Raises:
            WDARequestError
        """
        value = self.http.get('screenshot').value
        raw_value = base64.b64decode(value)
        png_header = b"\x89PNG\r\n\x1a\n"
        if not raw_value.startswith(png_header) and png_filename:
            raise WDARequestError(-1, "screenshot png format error")

        if png_filename:
            with open(png_filename, 'wb') as f:
                f.write(raw_value)

        if format == 'raw':
            return raw_value
        elif format == 'pillow':
            from PIL import Image
            buff = io.BytesIO(raw_value)
            im = Image.open(buff)
            return im.convert("RGB") # convert to RGB to fix save jpeg error
        else:
            raise ValueError("unknown format")
def screenshot ( self , png_filename = None , format = 'pillow' ) : value = self . http . get ( 'screenshot' ) . value raw_value = base64 . b64decode ( value ) png_header = b"\x89PNG\r\n\x1a\n" if not raw_value . startswith ( png_header ) and png_filename : raise WDARequestError ( - 1 , "screenshot png format error" ) if png_filename : with open ( png_filename , 'wb' ) as f : f . write ( raw_value ) if format == 'raw' : return raw_value elif format == 'pillow' : from PIL import Image buff = io . BytesIO ( raw_value ) im = Image . open ( buff ) return im . convert ( "RGB" ) # convert to RGB to fix save jpeg error else : raise ValueError ( "unknown format" )