博客
关于我
Android实现视屏与Base64互转
阅读量:256 次
发布时间:2019-03-01

本文共 1719 字,大约阅读时间需要 5 分钟。

1.视屏转Base64字符串

* 视屏转Base64字符串     * @param     * @return     */    private String fileBase64String(Uri url){           try {               InputStream fis = getContentResolver().openInputStream(url);;//转换成输入流            ByteArrayOutputStream baos = new ByteArrayOutputStream();            byte[] buffer = new byte[1024];            int count = 0;            while((count = fis.read(buffer)) >= 0){                   baos.write(buffer, 0, count);//读取输入流并写入输出字节流中            }            fis.close();//关闭文件输入流            return Base64.encodeToString(baos.toByteArray(),Base64.DEFAULT);        } catch (Exception e) {               Log.e(TAG, "错误--> " + e);            return null;        }    }

2.base64字符串转视屏

/**     * base64字符串转视屏     * videoFilePath  输出视频文件路径带文件名     */    public static void base64ToVideo(String base64) {           try {               //base解密            byte[] videoByte = Base64.decode(base64.getBytes(),Base64.DEFAULT);            File videoFile = new File(Environment.getExternalStorageDirectory()                    + "/Convert.mp4");            if (videoFile.exists()){                   videoFile.delete();            }            try {                   //创建文件                videoFile.createNewFile();            } catch (IOException e) {                   e.printStackTrace();                Log.e("creatXMLFileException",e.getMessage());            }            //输入视频文件            FileOutputStream fos = new FileOutputStream(videoFile);            fos.write(videoByte, 0, videoByte.length);            fos.flush();            fos.close();            Log.d(TAG,"视屏保存的地址--" + videoFile);        } catch (IOException e) {               Log.e(TAG,"base64转换为视频异常",e);        }    }

3.记得动态获取权限

转载地址:http://vsfa.baihongyu.com/

你可能感兴趣的文章
nginx负载均衡的五种算法
查看>>
Nginx负载均衡详解
查看>>
Nginx负载均衡(upstream)
查看>>
Vue中删除el-table当前行的方法
查看>>
nginx转发端口时与导致websocket不生效
查看>>
Nginx运维与实战(一)-Nginx不同场景使用方法
查看>>
Nginx运维与实战(二)-Https配置
查看>>
Nginx部署_mysql代理_redis代理_phoenix代理_xxljob代理_websocket代理_Nacos代理_内网穿透代理_多系统转发---记录021_大数据工作笔记0181
查看>>
nginx部署本地项目如何让异地公网访问?服务器端口映射配置!
查看>>
Nginx配置HTTPS服务
查看>>
Nginx配置https的一个误区(导致404错误)
查看>>
Nginx配置Https证书
查看>>
Nginx配置http跳转https
查看>>
Nginx配置ssl实现https
查看>>
nginx配置ssl证书https解决公网ip可以访问但是域名不行的问题
查看>>
Nginx配置TCP代理指南
查看>>
NGINX配置TCP连接双向SSL
查看>>
Nginx配置——不记录指定文件类型日志
查看>>
nginx配置一、二级域名、多域名对应(api接口、前端网站、后台管理网站)
查看>>
Nginx配置中root和alias分不清?本文3分钟帮你解惑!
查看>>