安卓:写PNG的ByteArray到文件 [英] Android: write PNG ByteArray to file

查看:286
本文介绍了安卓:写PNG的ByteArray到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一个图像文件到字节数组,但我怎么能写回来。我的意思的ByteArray保存到图像文件中的文件系统。 PNG格式preferred。

I have read an image file into ByteArray, but how can I write it back. I mean save ByteArray to image file in the file system. PNG format preferred.

我的code从PNG文件的ByteArray:

My code from PNG file to ByteArray:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), mUri);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

我知道有一些类似的问题,但我没有找到这一个确切的解决方案。谢谢!

I know there are some similar questions, but I didn't find the exact solution for this one. Thanks!!!

推荐答案

只需使用的FileOutputStream 来写你的字节数组。像这样的:

Just use a FileOutputStream to write your byte array into. Like this:

File file = new File(getFilesDir()+"/file.png");
FileOutputStream fos = new FileOutputStream(file);

//write your byteArray here
fos.write(byteArray);
fos.flush();
fos.close();

这篇关于安卓:写PNG的ByteArray到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆