当地读取图片转化为byte[]
本地读取图片转化为byte[]
public void read(){ String imagePath = "d:/lxp.bmp"; byte[] tmp = new byte[4096]; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); InputStream in = null; try { in = new FileInputStream(imagePath); int len; while((len = in.read(tmp)) != -1){ buffer.write(tmp,0,len); } imageData = buffer.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ try { if(in != null) in.close(); } catch (IOException e) { e.printStackTrace(); } } }