//返回图片的字节 public byte[] loadTexttureIcon(String path){ Bitmap image = BitmapFactory.decodeFile(path); ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] picture=baos.toByteArray(); byte[] data = picture; return data; } //保存图片 private void saveTexture(Bitmap bmp,String path) { //Bitmap bmp=BitmapFactory.decodeByteArray(data, 0, data.length); File file=new File(path); if(!file.exists()){ File vDirPath = file.getParentFile(); vDirPath.mkdirs(); try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file)); bmp.compress(Bitmap.CompressFormat.JPEG, 80, bos); try { bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } }
android的图片保存和读取
最新推荐文章于 2024-01-11 17:22:02 发布