public static byte[] getByte(String fileName) {
byte[] bt = null;
FileInputStream stream = null;
ByteArrayOutputStream out = null;
try {
stream = new FileInputStream(fileName);
out = new ByteArrayOutputStream(1000);
byte[] b = new byte[1000];
int len = 0;
while ((len = stream.read(b)) != -1) {
out.write(b, 0, len);
}
stream.close();
out.close();
bt = out.toByteArray();
Log.i("byteArray", ""+bt);
} catch (Exception e) {
e.printStackTrace();
try {
if (stream != null)
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if (out != null)
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
out = null;
return bt;
}
将读取的图片的InputStream流转为字节流
最新推荐文章于 2024-07-24 20:22:36 发布