开发者

android convert bitmap to bufferedinputstream

开发者 https://www.devze.com 2023-04-01 01:19 出处:网络
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 apa

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

精彩评论

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