/**
* 用字节流获取图片,把字节数组用ByteArrayOutputStream 写到 bao里面去,,可以返回一个字节数组
* @param path
* @return
*/
public static byte[] imgArry(String path){
InputStream inImg=null;
ByteArrayOutputStream bao=new ByteArrayOutputStream();
try {
inImg=new FileInputStream(path);
byte [] b=new byte[1024];
int len=-1;
//将图片的所有字节通过数组b读取出来在写到bao里面去
while((len=inImg.read(b))!=-1) {
bao.write(b, 0, len);
}
//返回bao字节数组
return bao.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
bao.close();
inImg.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
图片与数组转换
最新推荐文章于 2021-12-02 20:44:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)