1

I am using the Python Imaging Library to turn a photo into a byte array. This can be done by

im = Image.open("hello.jpg")
myImageArray = im.tobytes()

From the documentation, the tobytes function is defined by

def tobytes(self, encoder_name="raw", *args):
        """
        Return image as a bytes object

        :param encoder_name: What encoder to use.  The default is to
                             use the standard "raw" encoder.
        :param args: Extra arguments to the encoder.
        :rtype: A bytes object.
        """

In this answer, Jon Skeet says "In order to convert an image to a byte array you have to specify an image format". Is the encoder the image format?

When tobytes defaults to raw, does this mean it is encoded as .raw and would need to be decoded as a .raw to be interpreted correctly, or do they mean something else by raw? Would it be nonsensical to try to encode a JPEG file as a bitmap byte array (i.e.

im = Image.open("hello.jpg")
myImageArray = im.tobytes('not jpg encoder')
Community
  • 1
  • 1
jalconvolvon
  • 158
  • 1
  • 10
  • 1
    The other question is for C# although the same concept holds; however this question is particular to a library. There is probably a list of supported formats (and encoder name that support them). – user2864740 Oct 12 '15 at 20:55

0 Answers0