Skip to content

PyEncoder using self.im.tobytes() #7551

Answered by radarhere
duaneg3 asked this question in Q&A
Discussion options

You must be logged in to vote

buf1 = self.im.tobytes("raw")

The simplest way to do this would be to construct an image around the ImagingCore object.

buf1 = Image.Image()._new(self.im).tobytes("raw")

If you would like to work at a lower level, you could start extracting the code from tobytes() instead.

encoder = Image.core.raw_encoder(self.im.mode, self.im.mode)
encoder.setimage(self.im)
bufsize = max(65536, self.im.size[0] * 4)
bytes_consumed, errcode, data = encoder.encode(bufsize)
if errcode < 0:
	msg = f"encoder error {errcode} in tobytes"
	raise RuntimeError(msg)
buf1 = data

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@duaneg3
Comment options

Answer selected by duaneg3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants