图片 二进制 转换

来源:互联网 发布:易语言球球大作战源码 编辑:程序博客网 时间:2024/06/01 22:43
/**     * 将接收的字符串转换成图片保存     * @param imgStr base64格式的二进制流转换的字符串     * @param imgPath 图片的保存路径     * @param imgName 图片的名称     * @param imgType 图片类型     * @return      *      1:保存正常     *      0:保存失败     */    public static int saveToImgByStr(String imgStr,String imgPath,String imgName,String imgType){    int stateInt = 1;    try{    BASE64Decoder decoder=new BASE64Decoder();    byte[] bytes=decoder.decodeBuffer(imgStr);    File file=new File(imgPath,imgName+"."+imgType);    FileOutputStream fos=new FileOutputStream(file);    fos.write(bytes);    fos.flush();    fos.close();    System.out.println("图片生成成功");    }catch(Exception e){    e.printStackTrace();    stateInt=0;    System.out.println("图片生成失败");    }        return stateInt;    }

0 0
原创粉丝点击