saving a numpy array as a io.BytesIO with jpg format
<h3>I am using xlsxwriter to insert image into excel in python code.</h3>

<p>Now, I had image data(numpy array) after opencv process. I would like insert this image data to excel. But xlswriter only support io.BytesIO stream.</p>

<p>question: I don't know how to convert numpy array to <a href="https://docs.python.org/2/library/io.html#io.BytesIO" rel="nofollow">io.BytesIO</a> with jpg format. </p>

<p>I have trying numpy.tostring but without jpg format.</p>

<p>the code working well in below:
<code>
_f = open('test.jpg') # I would like to insert test.jpg
worksheet.insert_image('E2', 'abc.jpg', {'image_data': _f.read()})
</code></p>

<p>Anybody can help me ? thank you so much.</p>

<p>finally , I find out a solution. 
we can use <code>cv2.imencode</code> function to convert numpy array to a jpg format.</p>

<p>let's close this question. </p>

python excel opencv numpy