android convert bitmap to bufferedinputstream

Dee picture Dee · Aug 29, 2011 · Viewed 12.8k times · Source

Newb question;

I've got a bitmap in memory;

Private Bitmap MyPicture;

Then later, I fill that MyPicture from imager from the camera. I need to upload that photo using the FTP client from the apache commons.

fcon.storeFile("filename", new BufferedInputStream(MyPicture.????));

But the apache want a BufferedInputStream. How do I convert the memory Bitmap to a memory stream?

Thanks guys!

Answer

Dee picture Dee · Aug 30, 2011

This is what I was looking for;

ByteArrayOutputStream stream = new ByteArrayOutputStream();
si.Image.compress(CompressFormat.JPEG, 100, stream);
InputStream is = new ByteArrayInputStream(stream.toByteArray());

The last line was the missing link...