画像とByteストリームの相互転送
public void byteToImg(String bytes, String imagePath) throws IOException
{
byte[] buffer = Base64.decode(bytes); //
File file = new File(SDPATH + imagePath);
FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer);
fos.flush();
fos.close();
}
public String imgToByte(String imagePath) throws IOException {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(
SDPATH + imagePath));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
String uploadBuffer = new String(Base64.encode(out.toByteArray())); // Base64
in.close();
//byte[] content = out.toByteArray();
return uploadBuffer;
}
転載先:https://www.cnblogs.com/gfqFighting/archive/2012/04/30/2477268.html