根据文件路径获取文件转成byte[]
public byte[] convertImageToByte(String imagePath) {
File file = new File(imagePath);
FileInputStream fis = null;
ByteArrayOutputStream baos = null;
if (file.exists()) {
try {
fis = new FileInputStream(file);
baos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
baos.write(b, 0, n);
}
return baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}