Question

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!

Was it helpful?

Solution

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...

OTHER TIPS

Converting the bitmap to a byte array is as easy as:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
MyPicture.compress(Bitmap.CompressFormat.PNG, 100, baos);
baos.toByteArray();

And then you can create a BufferedInputStreamto write the bytes to your file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top