读书人

当地读取图片转化为byte[]

发布时间: 2012-07-25 09:43:06 作者: rapoo

本地读取图片转化为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();}}}

读书人网 >移动开发

热点推荐