SoFunction
Updated on 2024-10-30

Drawing How to get the binary stream of an image

Some times, we need to draw after the binary data stream, matplotlib does not provide the relevant api, through the source code view and Baidu, get the following method

import  as plt
import numpy as np
import io
x=(10)
y=x
#(x,y)
#canvas = plt.get_current_fig_manager().canvas
#()
fig=()
(x,y)
canvas=
# This code above has the same effect as the code commented out above

# Method 1
buffer = ()
canvas.print_png(buffer)
data=()
()
# Method 2
buf, size = canvas.print_to_buffer()
image = ('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
buffer=()
(buffer,'PNG')
data=()
()

with open('',mode='wb') as f:
(data)
#f=open('',mode='wb')
#(data)
#()

It's also possible to convert binary images into arrays if we want to.

buffer=()
(data)
img=(buffer)
img = (img)

Above this drawing The method of obtaining the binary stream of an image is all that I have shared with you, and I hope it will give you a reference, and I hope you will support me more.