开发者

android convert bitmap to bufferedinputstream

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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜